PHP common string processing function example analysis, PHP function example analysis
The examples in this article describe the commonly used string processing functions in PHP. Share it with everyone for your reference. The specific analysis is as follows:
Here are only a few simple and commonly used functions:
chop performs space removal processing, get_html_translation_table returns the conversion list to variables, and defines strings including HTML-encoded htmlentities, htmlspecialchars_decode defines strings containing HTML special characters, nl2br quotemeta rtrim, etc.
Definition and usage: The chop() function removes whitespace characters or other predefined characters from the end of a string. This function is an alias of the rtrim() function.
Syntax: chop(string,charlist), the code is as follows:
Copy code The code is as follows:
$str="i'm a teacher "; //Define string
$result=chop($str); //Execute space removal processing
echo $result; //Output result
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), the code is as follows:
Copy code The code is as follows:
$trans=get_html_translation_table(html_entities); //Return the conversion list to the variable
print_r($trans); //Output conversion table
$str="hallo &
& krmer"; //Define string
$encoded=strtr($str,$trans); //Search for characters
echo $encoded; //Output results
//
$str="a 'quote' is bold"; //Define a string including html encoding
echo htmlentities($str); //Output the processed string
echo htmlentities($str, ent_quotes); //Output result after adding optional parameters
//
$str='this -> "
'; //Define a string containing html special characters
echo htmlspecialchars_decode($str); //Output the converted content
echo "
";
echo htmlspecialchars_decode($str,ent_noquotes); //Output result without encoding quotes
//
$str="cat isn't n dog"; //Define a string containing newlines
$result=nl2br($str); //Perform conversion operation
echo $result; //Output the converted result
//
$str="hello world.(can you hear me?)"; //Define a string containing metacharacters
$result=quotemeta($str); //Perform conversion operation
echo $result; //Output the converted result
//
$str="hello world "; //Define a string with spaces at the end
$result=rtrim($str); //Perform conversion operation
echo $result; //Output the converted result
I hope this article will be helpful to everyone’s PHP programming design.
http://www.bkjia.com/PHPjc/916061.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/916061.htmlTechArticleAnalysis of examples of commonly used string processing functions in PHP, analysis of PHP function examples. This article describes examples of commonly used string processing functions in PHP. Share it with everyone for your reference. The specific analysis is as follows: Here...