Home >Backend Development >PHP Tutorial >Commonly used string processing functions in php_PHP tutorial

Commonly used string processing functions in php_PHP tutorial

WBOY
WBOYOriginal
2016-07-20 11:02:10991browse

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

get_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
//

$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 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
?>


http://www.bkjia.com/PHPjc/445386.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/445386.htmlTechArticleOnly a few simple and commonly used functions are provided below. Chop performs space removal processing, and get_html_translation_table returns the conversion list to variables. Definition Contains HTML-encoded string htmlentities, ...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn