Php string functions (1)

Source: Internet
Author: User
: This article mainly introduces php string functions (1). For more information about PHP tutorials, see. 1. clear spaces and characters on both sides of the string. the trim () function ()

$ Str = "hello, word"; echo $ str ."
"; Echo trim ($ str )."
"; $ Str =" @ dawn hello, word @ "; echo ltrim ($ str )."
"; Echo rtrim ($ str );

The result is as follows: ltrim () clears spaces and characters on the left, and rtrim () clears spaces and characters on the right.

2. escape string functions/addcslashes (str, ch) and stripcslashes (str );

$ Str = "select * from data where name = 'day1'"; $ strm = addcslashes ($ str, "'"); $ strl = stripcslashes ($ str ); echo $ str."
"; Echo $ strm ."
"; Echo $ strl;

The addcslashes (str, ch) function adds "/" to some specific characters in the string. str refers to the string to be escaped, and ch refers to the character to be escaped. The stripcslashes (str) function restores the string escaped by the addcslashes function.

III. search string functions/strstr () functions and strchr () functions

$str = "abc@123.com";$tem = strchr($str,"@");$tep = strstr($str, "@");$ten = strstr($str, "@",true);echo$str."
";echo$tem."
";echo$tep."
";echo$ten;

Strstr (str, ch ). String to be retrieved by str. ch indicates the character to be retrieved. if it is set to true, the left character of the character to be retrieved is returned. If this parameter is not set, the right character is returned. The strchr () function returns the right character.

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.