This article describes the PHP common string processing functions. Share to everyone for your reference. The specific analysis is as follows:
Here are just a few simple, common functions:
Chop performs the removal of whitespace processing, get_html_translation_table returns the conversion list to the variable, and defines a string that includes HTML encoding Htmlentities,htmlspecialchars_decode Defines a string containing HTML special characters, NL2BR Quotemeta RTrim, and so on.
Definition and Usage: the chop () function deletes white space characters or other predefined characters from the end of the string, the alias of the function's RTrim () function.
Syntax: Chop (string,charlist), code as follows:
Copy Code code as follows:
$str = "I ' m a teacher"; Define String
$result =chop ($STR); Perform removal of space processing
echo $result; Output results
Definition and Usage: the get_html_translation_table () function returns the translation table used by the htmlentities () and Htmlspecialchars () functions.
Syntax: get_html_translation_table (Function,quotestyle), code as follows:
Copy Code code as follows:
$trans =get_html_translation_table (html_entities); Return to convert list to variable
Print_r ($trans); Output conversion Table
$str = "Hallo & <frau> & Krmer"; Define String
$encoded =strtr ($str, $trans); Find characters
Echo $encoded; Output results
//
$str = "A ' quote ' is <b>bold</b>"; Defines a string that includes HTML encoding
echo htmlentities ($STR); Output a processed string
Echo htmlentities ($str, ent_quotes); With optional parameters, output results
//
$str = ' <p>this-> ' </p> '; Defines a string containing HTML special characters
echo Htmlspecialchars_decode ($STR); Output converted Content
echo "<br>";
Echo Htmlspecialchars_decode ($str, ent_noquotes); Output that does not encode quotes
//
$str = "Cat isn ' t n dog"; Defines a string that contains line breaks
$result =nl2br ($STR); Perform a conversion operation
echo $result; Result of output conversion
//
$str = "Hello World". (Can you hear me?) "; To define a string containing a meta character
$result =quotemeta ($STR); Perform a conversion operation
echo $result; Result of output conversion
//
$str = "Hello World"; Defines a string with spaces at the end
$result =rtrim ($STR); Perform a conversion operation
echo $result; Result of output conversion
I hope this article will help you with your PHP programming.