PHP Uložení souboru LOCK
Tato funkce smaže původní soubor a vytvoří nový.
Parametry jsou cesta k souboru a pole řádků.
Nakonec nastaví mod přístupu k souboru.
Parametry jsou cesta k souboru a pole řádků.
Nakonec nastaví mod přístupu k souboru.
/**
* Tato funkce smaže původní soubor a vytvoří nový.
* Parametry jsou cesta k souboru a pole řádků.
* Nakonec nastaví mod přístupu k souboru.
*
* @param string $fname
* @param array $poleVstup
*/
function createNewFile($fname, $poleVstup)
{ // BEGIN function createNewFile
if(file_exists($fname))unlink($fname);
$fp = fopen($fname, "a");
if (flock($fp, LOCK_EX)) { // do an exclusive lock
foreach ($poleVstup as $key=>$value) {
fwrite($fp, $value); //
}
flock($fp, LOCK_UN); // release the lock
} else {
echo "Couldn't lock the file !";
}
fclose($fp);
chmod($fname, 0777); // set CHMOD
} // END function createNewFile
/**
* 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
Od verze PHP 5.1.0 lze k uložení souboru se zámkem využít i funkci file_put_contents
přičemž flag bude mít hodnotu LOCK_EX
int file_put_contents ( string $filename , mixed $data [, int $flags = 0 [, resource $context ]] )
$file = "test.txt";
$content = "Some text which will put into file";
file_put_contents($file, $content, LOCK_EX);
77LW NO topic_id
AD
Další témata ....(Topics)
Některé funkce pracující s polem v JavaScriptu
var myArray = []; // smazat obsah, nebo inicializovat nove pole
concat([item1[, item2[, . . . [, itemN]]]])
concat([string2[, string3[, . . . [, stringN]]]])
/* spoji stringy nebo pole a vraci novy string nebo pole */
join(separator)
/* vrati v string spojene itemy poli oddelene separatorem*/
push([item1 [item2 [. . . [itemN ]]]])
/* prida na konec pole novy item a vraci delku pole*/
pop()
/* odebere posledni element z pole a vrati jeho hodnotu*/
reverse()
/*vraci obracene poradi itemu pole*/
shift()
/* odebere prvni item z pole a vrati jej*/
slice(start, [end])
/* varaci cast pole*/
var numArray = new Array(3,2,5,9);
var newNumArray = numArray.slice(1,3); // 2,5
sort() // string
sort(sortFunction)
/* setridi pole cisel od nejvetsiho - descending */
sort(function(a, b){return b-a})
/* setridi od nejmensiho cisla - ascendant*/
sort(function(a, b){return a-b})
splice(start, deleteCount, [item1[, item2[, . . . [,itemN]]]])
/* odebere element z pole, popripade vlozi novy a vrati odebrany element*/
var numArray = new Array(3,2,5,9);
var newNumArray = numArray.splice(1,1); // 3,5,9
unshift([item1[, item2 [, . . . [, itemN]]]])
/* prida na pocatek item, ktery je parametrem funkce */
var myA = new Array(10,11,12);
myA.unshift(1); // 1,10,11,12
V php se nevyhnete znalosti html kodu. Zde je šablona pro vytvoření kostry stránky. Charset UTF-8 zvládají všechny moderní prohlížeče, ale je nutné, aby soubor na serveru byl uložen v tomto formátu, jinak by došlo ke zkomolení diakritiky. Pokud budete používat jen češtinu na stránkách, můžete nastavit charset na "windows-1250", ale v dnešní době je to již krok zpět.
Pokud chceme zobrazit zdrojový kód určitého php souboru můžeme použít funkce show_source(__FILE__);
Pokud chceme zobrazit zdrojový kód určitého php souboru můžeme použít funkce show_source(__FILE__);
show_source(__FILE__);
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <meta name="description" content="zde bude popis stranky"> <meta name="keywords" content="zde, budou, klicova, slova, oddelena, carkou"> <title>Nazev stranky</title> </head> <body> <!--text a kod stranky--> </body> </html>
Foreach fore each in javascript loop cycle example source code
Example code foreach for JavaScript.
var arr = new Array(1,2,3,4,5,6);// numbers or string put into array
for (var key in arr) {
window.alert("My array"
+ key
+ " = "
+ arr[key]);
}
// next example
arr.forEach(function(elem){
console.log(elem);
});
// next example
for (var i = 0; i < arr.length; i++) {
alert (arr[i]);
}
// next example for GECKO MOZILLA FIREFOX
var soucet = 0;
var obj = {var1: 5, var2: 13, var3: 8};
for each (var item in obj) {
soucet += item;
}
alert(soucet); // vysledek "26", coz je soucet 5+13+8
Each in jQuery get all document inputs type text and set value 0 if checkbox checked
function fc(th){
if( th.checked ){
$("input:text").each(
function() {
this.value = 0;
this.disabled = true;
}
);
}else{
$("input:text").each(
function() {
this.disabled = false;
}
);
}
<input type="checkbox" id="idCheck" onchange="fc(this);"> Checkbox
<input type="text" size="1" id="id1" value="0" />
<input type="text" size="1" id="id2" value="0" />
// multiline string old school tip trick
// create elemnt div style none or hidden with text
var sMulitilineString = document.getElementById('idHiddenDiv').innerHTML; // get text from hidden div
// ES6 with quotes
const htmlString = 'Say hello to
multi-line
strings!';
(typeof "813") // string
(typeof 813) // number
parseInt("10.33") // returns 10 string to integer
parseInt('2def8'); // 2
parseInt('a2def8'); // NaN
parseFloat("10.33") // returns 10.33 string to float
var test_1 = 'string';
var test_2 = ' example';
var suma = test_1 + test_2;
var length = suma.length; // 14
var le = test_1.length; // 6
charAt(index)
/* Returns the character at the specified index */
var str = new String('Sample');
str.charAt(3)); // p
// startsWith
var str = "HELLO WORLD";
var res = str.charAt(0); // H
// endsWith
var res = str.charAt(str.length - 1); // D
charCodeAt(index)
/* Returns an integer representing the Unicode encoding
of the character at the specified location */
var str = new String('Sample');
str.charCodeAt(3)); // 112
fromCharCode([code1[, code2[, ...[, codeN]]]])
/* Returns a string from a number of Unicode character values */
var e = window.event;
var str = String.fromCharCode(e.keyCode); // keydown etc.
concat([item1[, item2[, . . . [, itemN]]]])
/* Returns a new array consisting of a combination of two or more arrays */
var arr1 = new Array("Hello, ", "Dolly uranove");
var arr2 = new Array("World!", "dort");
var myConcatArray = arr1.concat(arr2);
alert(myConcatArray[3]); // dort
concat([string2[, string3[, . . . [, stringN]]]])
/* Returns a string value containing the concatenation
of two or more supplied strings */
var string1 = new String("Hello, ");
var string2 = new String("World!");
var myConcatString = string1.concat(string2); // Hello, World!
indexOf(subString[, startIndex])
/* Returns the character position where the first occurrence
of a substring occurs within a String object */
lastIndexOf(substring[, startindex])
/* Returns the last occurrence of a substring within a String object */
localeCompare(stringExp)
/* Returns a value indicating whether two strings
are equivalent in the current locale */
var str1 = "1";
var str2 = "2";
var n = str1.localeCompare(str2); // -1
var str1 = "2";
var str2 = "2";
var n = str1.localeCompare(str2); // 0
var str1 = "a";
var str2 = "b";
var n = str1.localeCompare(str2); // -1
var str1 = "b";
var str2 = "a";
var n = str1.localeCompare(str2); // 1
match(rgExp)
/* Executes a search on a string using a regular expression
pattern, and returns an array containing the results of that search */
var rgExp = /some text/g;
replace(rgExp, replaceText)
/* Returns a copy of a string with text replaced
using a regular expression or search string */
search(rgExp)
/* Returns the position of the first substring
match in a regular expression search */
n // A newline character
. // Any character except a newline
r // A carriage return character
t // A tab character
b // A word boundary (the start or end of a word)
B // Anything but a word boundary
d // Any digit (same as [0-9])
D // Anything but a digit (same as [^0-9])
s // Single whitespace (space, tab, newline, etc.)
S // Single nonwhitespace
w // A "word character” (same as [A-Za-z0-9_])
W // A "nonword character” (same as [^A-Za-z0-9_])
slice(start, [end])
/* Returns a section of an array or string */
var myString = new String("This is a test");
var mySlice = myString.slice(2,6); // is i // pos: 2 to 5 // 0==T, 1==h, 2==i, 3==s, 4==" ", 5==i
mySlice = myString.slice(-3); // est // end of string
mySlice = myString.slice(0); // This is a test
split([separator[, limit]])
/* Returns the array of strings that results
when a string is separated into substrings */
var str = "one two three";
var words = str.split(" ");
var len = words.length; // 3
substring(start, end)
/* Returns the substring at the specified location
within a String object */
var inpTxt = "Hello there";
alert(inpTxt.substring(6, 10)); // ther
substr(start [, length ])
// Returns a substring beginning at a specified
// location and having a specified length
var s = "The love in Spain.";
ss = s.substr(12, 5); // Spain
tolocaleLowerCase()
/* Returns a string where all alphabetic characters
have been converted to lowercase, taking into account
the host environment's current locale */
toUpperCase()
/* Returns a string where all alphabetic characters
have been converted to uppercase */
var myString = "My text";
myString.anchor //places an HTML anchor with a NAME attribute around specified text in the object
myString.big
myString.blink
myString.bold
myString.concat
myString.fixed
myString.fontcolor
myString.fontsize
myString.charAt
myString.charCodeAt
myString.indexOf
myString.italics
myString.lastindexOf
myString.length
myString.link
myString.match
myString.replace
myString.search
myString.slice
myString.small
myString.split
myString.strike
myString.sub //places HTML SUB tags around text in a String object
myString.substr
myString.substring
myString.sup
myString.toLowerCase
myString.toString
myString.toUpperCase
myString.valueOf
var str = "58";
var res = str.valueOf();
var type = (typeof res); // string
var str = 58;
var res = str.valueOf();
var type = (typeof res); // number
Získání IP adresy v PHP.
$serverIP=$_SERVER['REMOTE_ADDR'];
echo "document.write("Your IP address is: <b>" . $serverIP . "</b>")";
Editace: 18 10 2016
Počet článků v kategorii: 77
Url:php-ulozeni-souboru-lock