: 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.