Summary of PHP character processing functions _ PHP Tutorial

Source: Internet
Author: User
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

  1. $ Zero = "0 ";
  2. $ Za = array ("00 ");
  3. If (in_array ($ zero, $ za, true )){
  4. Echo 'In ';
  5. } Else {
  6. Echo 'not in ';
  7. }
  8. $ Zero = "0 ";
  9. $ Za = array ("00 ");
  10. If (in_array ($ zero, $ za, true )){
  11. Echo 'In ';
  12. } Else {
  13. Echo 'not in ';
  14. }

What should this code output? The answer is in, not in.
Then test this:

Java code

 
 
  1. $zero = "0";
  2. $za = array("00");
  3. if("0" == "00"){
  4. echo '0 == 00';
  5. }
  6. $zero = "0";
  7. $za = array("00");
  8. if("0" == "00"){
  9. echo '0 == 00';
  10. }

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

 
 
  1. urldecode(strtolower
    (urlendoce($str)));
  2. 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

 
 
  1. function cntrim($value){
  2. return trim(ereg_replace("^(
     )*|( )*$","", $value));
  3. }
  4. function cntrim($value){
  5. return trim(ereg_replace("^( 
    )*|( )*$","", $value));
  6. }

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

 
 
  1. function non_szero_empty
    ($value){
  2. return empty($value) &&
    $value != '0';
  3. }
  4. function non_szero_empty
    ($value){
  5. return empty($value) &&
    $value != '0';
  6. }

PHP character handler function 5. htmlentities ():

Similar to strtolower (), htmlentities may also encounter escape gbk characters, resulting in garbled characters. Simply replace:

Java code

 
 
  1. function _myhtmlentities($value){
  2. //$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));
  3. $value = str_replace(array('&', '"',
    '< ', '>'), array('&', '"',
    '<', '>'), $value);
  4. return $value;
  5. }
  6. function _myhtmlentities($value){
  7. //$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));
  8. $value = str_replace(array('&', '"',
    '< ', '>'), array('&', '"',
    '<', '>'), $value);
  9. return $value;
  10. }

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...

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.