Difference between revisions of "PHP"
From Alessandro's Wiki
Line 1: | Line 1: | ||
== server == | == server == | ||
* The eAccelerator and XCache PHP performance extensions are known to cause issues. If you're using either of those and are having problems, please disable them while you do your import. Add the following lines: | * The eAccelerator and XCache PHP performance extensions are known to cause issues. If you're using either of those and are having problems, please disable them while you do your import. Add the following lines: | ||
<syntaxhighlight lang="php" > | |||
php_value eaccelerator.enable 0 | php_value eaccelerator.enable 0 | ||
php_value xcache.cacher off | php_value xcache.cacher off | ||
php_value xcache.optimizer off | php_value xcache.optimizer off | ||
</syntaxhighlight> | |||
=== Syntax === | === Syntax === | ||
==== if ==== | ==== if ==== | ||
<syntaxhighlight> | <syntaxhighlight lang="php" > | ||
if ( ( $A != "null" ) && (( $A === "true" ) || ( $A == "true" ) || ( $A <= 12 ) ) ) { | if ( ( $A != "null" ) && (( $A === "true" ) || ( $A == "true" ) || ( $A <= 12 ) ) ) { | ||
/* code code code */ | /* code code code */ | ||
Line 20: | Line 20: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
* abbreviation (as in C): | * abbreviation (as in C): | ||
<syntaxhighlight lang="php" > | |||
(something) ? (if true do this) : (else do this) | (something) ? (if true do this) : (else do this) | ||
</syntaxhighlight> | |||
==== for / foreach ==== | ==== for / foreach ==== | ||
==== switch ==== | ==== switch ==== | ||
<syntaxhighlight lang="php" > | |||
switch ($something) { | switch ($something) { | ||
case 0: | case 0: | ||
Line 34: | Line 34: | ||
break; | break; | ||
} | } | ||
</syntaxhighlight> | |||
==== Strings ==== | ==== Strings ==== | ||
* joining strings: | * joining strings: | ||
<syntaxhighlight lang="php" > | |||
$string1 . "string 2" . $_GLOBAL['string3']; | $string1 . "string 2" . $_GLOBAL['string3']; | ||
</syntaxhighlight > | |||
==== Array ==== | ==== Array ==== | ||
* basic | * basic | ||
<syntaxhighlight lang="php" > | |||
Array("one", "two", "3" ); | Array("one", "two", "3" ); | ||
</syntaxhighlight> | |||
* with index: | * with index: | ||
<syntaxhighlight lang="php" > | |||
Array( 1 => "one", 2 => "two", 3 => "3" ); | Array( 1 => "one", 2 => "two", 3 => "3" ); | ||
</syntaxhighlight > | |||
* 2 dimensions | * 2 dimensions | ||
Line 53: | Line 58: | ||
« » ò ó á à è é ù ú ì í ñ · ç : . , ! “ ” ' ' € & ' @ % $ ? | « » ò ó á à è é ù ú ì í ñ · ç : . , ! “ ” ' ' € & ' @ % $ ? | ||
171,187,242,243,225,224,232,233,249,250,236,237,241,183,231,58,46,44,33,145,146,147,148,128,38,39,64,37,36,63 | 171,187,242,243,225,224,232,233,249,250,236,237,241,183,231,58,46,44,33,145,146,147,148,128,38,39,64,37,36,63 | ||
<syntaxhighlight lang="php" > | |||
function UrlizzaTit( $titoloUTF ) { | function UrlizzaTit( $titoloUTF ) { | ||
// Caratteri o stringhe da rimpiazzare col segno + | // Caratteri o stringhe da rimpiazzare col segno + | ||
Line 115: | Line 120: | ||
return $urlizzato; | return $urlizzato; | ||
</syntaxhighlight> | |||
} | } | ||
Revision as of 09:05, 7 July 2011
server
- The eAccelerator and XCache PHP performance extensions are known to cause issues. If you're using either of those and are having problems, please disable them while you do your import. Add the following lines:
php_value eaccelerator.enable 0
php_value xcache.cacher off
php_value xcache.optimizer off
Syntax
if
if ( ( $A != "null" ) && (( $A === "true" ) || ( $A == "true" ) || ( $A <= 12 ) ) ) {
/* code code code */
}
else
{
/* code code code */
}
- abbreviation (as in C):
(something) ? (if true do this) : (else do this)
for / foreach
switch
switch ($something) {
case 0:
echo "something is 0";
break;
case "hello":
echo "something is $something";
break;
}
Strings
- joining strings:
$string1 . "string 2" . $_GLOBAL['string3'];
Array
- basic
Array("one", "two", "3" );
- with index:
Array( 1 => "one", 2 => "two", 3 => "3" );
- 2 dimensions
My algorithms
Cleaning strings for links
Funzione per ripulire i titoli degli articoli da mettere nelle url « » ò ó á à è é ù ú ì í ñ · ç : . , ! “ ” ' ' € & ' @ % $ ? 171,187,242,243,225,224,232,233,249,250,236,237,241,183,231,58,46,44,33,145,146,147,148,128,38,39,64,37,36,63
function UrlizzaTit( $titoloUTF ) {
// Caratteri o stringhe da rimpiazzare col segno +
$toPlus = array(
chr(32),
chr(145),
chr(146),
chr(37),
chr(123),
chr(125),
chr(39),
chr(64),
chr(33),
chr(36),
chr(63),
";",
"[",
"]",
"(",
")",
"\n",
"-"
);
// Caratteri o stringhe da cancellare
$toNull = array(
"Il ",
"Lo ",
"lo ",
"da ",
" I ",
" i ",
" l' ",
chr(147),
chr(148),
chr(171),
chr(187),
chr(58),
chr(44),
chr(46)
);
$urlizzato1 = str_replace(chr(231),"c",
str_replace(chr(249),"u",
str_replace(chr(250),"u",
str_replace(chr(242),"o",
str_replace(chr(243),"o",
str_replace(chr(225),"a",
str_replace(chr(224),"a",
str_replace(chr(232),"e",
str_replace(chr(233),"e",
str_replace(chr(128),"euro+eur",
str_replace(chr(236),"i",
str_replace(chr(237),"i",
str_replace(chr(241),"n",
str_replace(chr(38),"and", $titoloUTF ))))))))))))));
$urlizzato2 = str_replace( $toNull, "" , $urlizzato1 );
$urlizzato = str_replace( $toPlus, "+" , $urlizzato2 );
return $urlizzato;
}
Others algorithms
simple glob() type replacement:
$files = preg_find('/./', $dir);
recursive?
$files = preg_find('/./', $dir, PREG_FIND_RECURSIVE);
pattern match? find all .php files:
$files = preg_find('/\.php$/D', $dir, PREG_FIND_RECURSIVE);
sorted alphabetically?
$files = preg_find('/\.php$/D', $dir, PREG_FIND_RECURSIVE|PREG_FIND_SORTKEYS);
sorted in by filesize, in descending order?
$files = preg_find('/./', $dir, PREG_FIND_RECURSIVE|PREG_FIND_RETURNASSOC |PREG_FIND_SORTFILESIZE|PREG_FIND_SORTDESC); $files=array_keys($files);
sorted by date modified?
$files = preg_find('/./', $dir, PREG_FIND_RECURSIVE|PREG_FIND_RETURNASSOC |PREG_FIND_SORTMODIFIED); $files=array_keys($files);