PHP Načtení souboru do stringu
Pokud často pracujete v PHP se soubory, tak se Vám může hodit
tato funkce, která vrací obsah souboru, jako string, narozdíl od funkce
file(), která vrací obsah souboru, jako pole řádků.
tato funkce, která vrací obsah souboru, jako string, narozdíl od funkce
file(), která vrací obsah souboru, jako pole řádků.
/**
* function return file content as string
* $filename is path to file
*/
function getContents($filename) {
if (function_exists('file_get_contents')) {
return file_get_contents($filename);
} else {
$fp = fopen($filename, 'r');
if (!$fp) {
echo ('Could not read contents <br/>');
return false;
}
return fread($fp, filesize($filename)); // return string
}
}
/**
* function file return file content as an array of rows
*/
$rows = file($filename);
/**
* fopen() modes
*/
r Read
r+ Read and write, prepend
w Write, truncate
w+ Read and write, truncate
a Write, append
a+ Read and write, append
77LW NO topic_id
AD
Další témata ....(Topics)
CORS-Cross-Origin-Resource-Sharing Header set Access-Control-Allow-Origin Source Code Example
Usefull Links here
https://www.w3.org/wiki/CORS_EnabledApache .htaccess Allow File Types
<IfModule mod_setenvif.c>
<IfModule mod_headers.c>
<FilesMatch ".(bmp|cur|gif|ico|jpe?g|png|svgz?|webp)$">
SetEnvIf Origin ":" IS_CORS
Header set Access-Control-Allow-Origin "*" env=IS_CORS
</FilesMatch>
</IfModule>
</IfModule>
.htaccess which is closest to the file!!!!!
Date: 17.06.2020 - 08:09
var 1_radian_to_degree = 180 / Math.PI; // 57,295779513082320876798154814105 degree
var 1_degree_to_radian = Math.PI / 180; // 0,01745329251994329576923690768489 radian
var 360_degree = 2 * Math.PI * 1_radian_to_degree;
var degree = 36.86;
var opposite = 600;
var hypotenuse = 1000;
var adjacent = 800;
// degree
// sin 45° == 0.7071067811865475;
var sin = Math.sin(45 * Math.PI / 180.0)
//sin == 0.7071067811865475;
// vypocet prepony (hypotenuse), kdyz zname
// protilehlou (opposite) a uhel (degree)
hypotenuse2 = opposite/ Math.sin(degree * Math.PI / 180.0);
// vypocet protilehle (opposite)
opposite2 = hypotenuse * Math.sin(degree * Math.PI / 180);
// vypocitat uhel alfa z velikosti protilehle a prepony ve stupnich (degree)
degree2 = Math.asin(opposite / hypotenuse)* (180/Math.PI); // 1rad
// velikost prepony pomoci prilehle (adjacent) strany a cos a uhlu v stupnich (degree)
hypotenuse3 = adjacent / Math.cos(degree * Math.PI / 180);
// velikost prilehle (adjacent) strany pomoci prepony a cos a uhlu v stupnich (degree)
adjacent2 = hypotenuse * Math.cos(degree * Math.PI / 180);
tan = Math.tan(degree * Math.PI/180); // 45° == 0.9999999999999
degree3 = Math.atan(opposite / adjacent)* (180/Math.PI); // 1rad
adjacent3 = opposite / Math.tan(degree * Math.PI / 180);
opposite3 = adjacent * Math.tan(degree * Math.PI / 180);
Jak vybrat kód mezi taky v Notepad++
How to select f.e. javascript tag contetn in Notepad++
- insert content between braces
- put caret behind the last bracket
- press Ctrl + left Alt + B or Ctrl + Shift + B to control the first brace
from parentheses to braces and check the multi-line box.
Then you can Ctrl-double-click on either brace to highlight everything in between.
How to select f.e. javascript tag contetn in Notepad++
- insert content between braces
- put caret behind the last bracket
- press Ctrl + left Alt + B or Ctrl + Shift + B to control the first brace
< script>
{
var bla = 0;
// bla bla ... long content
} // place caret/cursor behind the last brace { and press Ctrl + left Alt + B (Notepad++)
< /script>
At Settings->Preferences->Delimiter, change the delimiters
from parentheses to braces and check the multi-line box.
Then you can Ctrl-double-click on either brace to highlight everything in between.
Letní čas tak připočítat hodinu.
Ověření zda je letní čas.
$dst = date("I"); //I (capital i); 0 or 1 if daylight saving time
// example:
$hour = 14;
if(date("I")===1){
$hour = $hour + 1;
}
// OR
$hour = 14 + date("I");
Getter a Setter
Získej nebo Nastav.
Michal už není Váš kamarád, tak jej změníte pomocí set:
Získej nebo Nastav.
Třídy v javascript dovolují použití get a set instrukci.
get vrátí hodnotu určité zadané proměnné.
set jí může změnit.
class Person {
constructor(name) {
this.personName = name;
}
get pname() {
return this.personName;
}
// i kdyz set vypada jako funkce, musi mit pouze jeden parametr
set pname(x) {
this.personName = x;
}
}
var myFriend = new Person("Michael");
Jméno osoby přítele získáme například:
var strMyFriendName = myFriend.pname; // bez () na konci!!!!!!
alert(strMyFriendName);
Michal už není Váš kamarád, tak jej změníte pomocí set:
// hodnota se nepřirazuje do závorek (), ale pomocí = rovná se!!!!
myFriend.pname = "Renata";
strMyFriendName = myFriend.pname;
alert(strMyFriendName);
Editace: 18 10 2016
Počet článků v kategorii: 77
Url:php-nacteni-souboru-do-stringu