_php tutorials for commonly used string processing functions in PHP

Source: Internet
Author: User
Tags chop rtrim
Here are just a few simple and common functions, chop performs the removal of whitespace processing, get_html_translation_table returns a conversion list to a variable, and defines a string that includes HTML encoding Htmlentities,htmlspecialchars_ Decode defines strings that contain HTML special characters, NL2BR Quotemeta RTrim, and so on.

Here are just a few simple and common functions, chop performs the removal of whitespace processing, get_html_translation_table returns a conversion list to a variable, and defines a string that includes HTML encoding Htmlentities,htmlspecialchars_ Decode defines strings that contain HTML special characters, NL2BR Quotemeta RTrim, and so on.
Definition and usage
The chop () function removes whitespace characters or other predefined characters starting at the end of the string.

The alias of the function's RTrim () function.

Grammar

Chop (string,charlist)

*/
$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.

Grammar
Get_html_translation_table (Function,quotestyle)

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


http://www.bkjia.com/PHPjc/445386.html www.bkjia.com true http://www.bkjia.com/PHPjc/445386.html techarticle here are just a few simple and common functions, chop do the removal of whitespace processing, get_html_translation_table return the conversion list to the variable, the definition includes HTML encoded string htmlentities, ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.