PHP Common string processing function instance analysis, PHP function Example analysis
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 and common functions:
Chop performs the removal of whitespace processing, get_html_translation_table returns the conversion list to the variable, and defines the string that includes the HTML encoding Htmlentities,htmlspecialchars_decode Defines a string that contains HTML special characters, NL2BR Quotemeta RTrim, and so on.
Definition and Usage: the chop () function removes whitespace characters or other predefined characters from the end of the string, and aliases the function's RTrim () function.
Syntax: Chop (string,charlist), the code is as follows:
Copy the Code code as follows: $str = "I ' m a teacher"; Defining strings
$result =chop ($STR); Perform a whitespace removal process
echo $result; Output results
Definition and Usage: the get_html_translation_table () function returns the translation tables used by the htmlentities () and Htmlspecialchars () functions.
Syntax: get_html_translation_table (Function,quotestyle), the code is as follows:
Copy the Code code as follows:
$trans =get_html_translation_table (html_entities); Return a conversion list to a variable
Print_r ($trans); Output conversion Table
$str = "Hallo & & Krmer";//define String
$encoded =strtr ($str, $trans); Find characters
Echo $encoded; Output results
//
$str = "A ' quote ' is bold"; Defines a string that includes HTML encoding
echo htmlentities ($STR); Output a processed string
Echo htmlentities ($str, ent_quotes); Output after adding optional parameters
//
$str = '
This, "
'; Defines a string that contains HTML special characters
echo Htmlspecialchars_decode ($STR); Output the converted Content
echo "
";
Echo Htmlspecialchars_decode ($str, ent_noquotes); Output that does not encode quotes
//
$str = "Cat isn ' t n dog"; Defines a string that contains a newline character
$result =nl2br ($STR); Perform a conversion operation
echo $result; Output converted Results
//
$str = "Hello World". (Can you hear me?) "; Defines a string containing metacharacters
$result =quotemeta ($STR); Perform a conversion operation
echo $result; Output converted Results
//
$str = "Hello World"; Defines a string with spaces at the end
$result =rtrim ($STR); Perform a conversion operation
echo $result; Output converted Results
I hope this article is helpful to everyone's PHP programming.
http://www.bkjia.com/PHPjc/916061.html www.bkjia.com true http://www.bkjia.com/PHPjc/916061.html techarticle php commonly used string processing function instance analysis, PHP function Example Analysis of the example of PHP commonly used string processing functions. Share to everyone for your reference. The specific analysis is as follows: here ...