Home >Backend Development >PHP Tutorial >Commonly used string processing functions in php_PHP tutorial
Only a few simple and commonly used functions are provided below. Chop performs space removal processing, get_html_translation_table returns the conversion list to variables, defines htmlentities including HTML-encoded strings, htmlspecialchars_decode defines strings containing HTML special characters, nl2br quotemeta rtrim, etc.
Only a few simple and commonly used functions are provided below. Chop performs space removal processing, get_html_translation_table returns the conversion list to variables, defines htmlentities including html-encoded strings, 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 starting from the end of a string.
An alias for the rtrim() function of this function.
Grammar
/*/chop(string,charlist)
*/
$str="i'm a teacher "; //Define string
$result=chop($str); //Execute space removal processing
return
Definition and usage
The get_html_translation_table() function returns the translation table used by the htmlentities() and htmlspecialchars() functions.
Grammar$str="a 'quote' isget_html_translation_table(function,quotestyle)
/*/
$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 character
echo $encoded; //Output result
//
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='
'; //Define a string containing html special characters
echo htmlspecialchars_decode($str); //Output the converted content//
$str="cat isn't n dog"; //Define a string containing a newline character
$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
?>