Summary of PHP character processing functions. We are learning PHP character processing functions 1. in_array () function Java code $ zero0; $ zaarray (00); if (in_array ($ zero, $ za, true) {echoin;} else {echonotin;} $ zero0; $ za we are learning
PHP character processing function 1. in_array () function
Java code
- $ Zero = "0 ";
- $ Za = array ("00 ");
- If (in_array ($ zero, $ za, true )){
- Echo 'In ';
- } Else {
- Echo 'not in ';
- }
- $ Zero = "0 ";
- $ Za = array ("00 ");
- If (in_array ($ zero, $ za, true )){
- Echo 'In ';
- } Else {
- Echo 'not in ';
- }
What should this code output? The answer is in, not in.
Then test this:
Java code
- $zero = "0";
- $za = array("00");
- if("0" == "00"){
- echo '0 == 00';
- }
- $zero = "0";
- $za = array("00");
- if("0" == "00"){
- echo '0 == 00';
- }
Returns '0' = '00 '.
So pay attention to the following: if the string is not in, it indicates that the character is in the array.
PHP character handler function 2. strtolower () function
My solution is:
Java code
- urldecode(strtolower
(urlendoce($str)));
- urldecode(strtolower
(urlendoce($str)));
PHP character processing function 3. trim ()
If you are dealing with English characters, trim () should be satisfied, but for Chinese characters, you should overwrite the space with trim to remove the full angle:
Java code
- function cntrim($value){
- return trim(ereg_replace("^(
)*|( )*$","", $value));
- }
-
- function cntrim($value){
- return trim(ereg_replace("^(
)*|( )*$","", $value));
- }
PHP character handler function 4. empty ():
This is a bit like the in_array () above. if you want to determine whether there is a value in a textarea, you cannot simply use empty, because the '0' string will also return empty (but the strange thing is that '00' will not return empty), rewrite to deal with this situation:
Java code
- function non_szero_empty
($value){
- return empty($value) &&
$value != '0';
- }
-
- function non_szero_empty
($value){
- return empty($value) &&
$value != '0';
- }
PHP character handler function 5. htmlentities ():
Similar to strtolower (), htmlentities may also encounter escape gbk characters, resulting in garbled characters. Simply replace:
Java code
- function _myhtmlentities($value){
- //$value = preg_replace('/&
((#(d{3,5}|x[a-fA-F0-9]{4})|
[a-zA-Z][a-z0-9]{2,5});)/', '&\1'
, str_replace(array('&', '"', '< ', '>')
, array('&', '"', '<',
'>'), $value));
- $value = str_replace(array('&', '"',
'< ', '>'), array('&', '"',
'<', '>'), $value);
- return $value;
- }
- function _myhtmlentities($value){
- //$value = preg_replace('/&((#(
d{3,5}|x[a-fA-F0-9]{4})|[a-zA-Z][a-
z0-9]{2,5});)/', '&\1', str_replace
(array('&', '"', '< ', '>'), array(
'&', '"', '<', '>'), $value));
- $value = str_replace(array('&', '"',
'< ', '>'), array('&', '"',
'<', '>'), $value);
- return $value;
- }
However, I am still wondering why htmlentities are garbled and why it is feasible to change it. The plan has time to check the source code.
The above is all the content of the PHP character processing function we will introduce to you this time.
Handler PHP character processing function 1. in_array () function Java code $ zero = 0; $ za = array (00); if (in_array ($ zero, $ za, true) {echo 'In ';} else {echo 'notin ';} $ zero = 0; $ za...