Common php string processing function instance analysis, php function instance Analysis _ PHP Tutorial

Source: Internet
Author: User
Tags chop
Common php string processing function instance analysis and php function instance analysis. Examples of common php string processing functions are analyzed. Examples of common php string processing functions are described in this article. Share it with you for your reference. The specific analysis is as follows: Examples of common php string processing functions are analyzed here, and examples of php functions are analyzed.

This example describes common php string processing functions. Share it with you for your reference. The specific analysis is as follows:

Here, only a few simple and common functions are provided:
Chop removes spaces. get_html_translation_table returns the conversion list to the variable. it defines the HTML-encoded string htmlentities, htmlspecialchars_decode, and defines the string containing special HTML characters, nl2br quotemeta rtrim, and so on.

Definition and usage: the chop () function deletes the white space or other pre-defined characters from the end of the string, the alias of the rtrim () function of the function.

Syntax: chop (string, charlist). The code is as follows:

The code is as follows:

$ Str = "I'm a teacher"; // define a string
$ Result = chop ($ str); // you can remove spaces.
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:

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 a string
$ Encoded = strtr ($ str, $ trans); // search for characters
Echo $ encoded; // output result
//

$ Str = "a 'quote' is Bold"; // Define a string that includes html encoding
Echo htmlentities ($ str); // output the processed string
Echo htmlentities ($ str, ent_quotes); // output result after an optional parameter is added

//
$ Str ='

This->"

'; // Define a string containing special html characters
Echo htmlspecialchars_decode ($ str); // output the converted content
Echo"
";
Echo htmlspecialchars_decode ($ str, ent_noquotes); // output results without the quotation marks being encoded

//

$ Str = "cat isn't n dog"; // defines a string containing a linefeed.
$ Result = nl2br ($ str); // perform the conversion operation.
Echo $ result; // output the converted result

//

$ Str = "hello world. (can you hear me ?) "; // Define a string containing metacharacters
$ Result = quotemeta ($ str); // execute the conversion operation
Echo $ result; // output the converted result
//

$ Str = "hello world"; // defines a string with spaces at the end
$ Result = rtrim ($ str); // execute the conversion operation
Echo $ result; // output the converted result

I hope this article will help you with php programming.

Examples in this article describes common php string processing functions. Share it with you for your reference. The specific analysis is as follows: here...

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.