PHP: Difference between revisions

From miki
Jump to navigation Jump to search
No edit summary
Line 17: Line 17:
NULL; // The null reference
NULL; // The null reference
</source>
</source>

== Unicode support ==
* First, if PHP file contains special character, make sure the PHP file is encoded in UTF-8:
<source lang=bash>
file -bi FenTT.php # To get current encoding
iconv -f $encoding -t UTF-8 -o FenTT.out.php FenTT.php # Specify correct source $encoding as given above (note that converting us-ascii is useless)
</source>
* Specify the default multi-byte encoding:
<source lang=bash>
mb_internal_encoding("UTF-8");
</source>
* Next store unicode char as follows [http://stackoverflow.com/questions/6058394/unicode-character-in-php-string]:
<source lang=bash>
$S = '\u2654\u2655\u2656\u2657';
$S = json_decode('"'.$S.'"');
</source>
* Then access the string using the multi-byte API, like:

Revision as of 05:25, 2 January 2016

References

TBC

Syntax

/* arrays */
$attr = array();          // an empty array
$attr = array("border"=>"myborder", "mode"=>"mymode");   // associative array

/* strings */
'abc' . 'def'                                     // concatenation
"abc $var def"                                    // variable reference in strings
$s=str_replace("\n","",$s);                       // Replace a substring in a string
$s=str_replace(array("\r","\n","\t"," "),"",$s;   // ... idem, with several substrings (also support several "replace" strings)

/* constant */
NULL;              // The null reference

Unicode support

  • First, if PHP file contains special character, make sure the PHP file is encoded in UTF-8:
file -bi FenTT.php           # To get current encoding
iconv -f $encoding -t UTF-8 -o FenTT.out.php FenTT.php        # Specify correct source $encoding as given above (note that converting us-ascii is useless)
  • Specify the default multi-byte encoding:
mb_internal_encoding("UTF-8");
  • Next store unicode char as follows [1]:
$S = '\u2654\u2655\u2656\u2657';
$S = json_decode('"'.$S.'"');
  • Then access the string using the multi-byte API, like: