Home > Article > Backend Development > php string function (1)
1 , functions to escape strings/addcslashes(str,ch) and stripcslashes(str);
<code><span>$str</span> = <span>" hello,word "</span>; <span>echo</span><span>$str</span>.<span>"<br/>"</span>; <span>echo</span> trim(<span>$str</span>).<span>"<br/>"</span>; <span>$str</span> = <span>"@黎明hello,word@"</span>; <span>echo</span> ltrim(<span>$str</span>).<span>"<br/>"</span>; <span>echo</span> rtrim(<span>$str</span>); </code>addcslashes(str,ch) function is to add "/" before some specific characters in the string, str means that they need to be converted Meaningful string, ch refers to the escaped character. The stripcslashes(str) function restores the string escaped by the addcslashes function
<code><span>$str</span> = <span>"select * from data where name ='黎明'"</span>; <span>$strm</span> = addcslashes(<span>$str</span>, <span>"'"</span>); <span>$strl</span> = stripcslashes(<span>$str</span>); <span>echo</span><span>$str</span>.<span>"<br/>"</span>; <span>echo</span><span>$strm</span>.<span>"<br/>"</span>; <span>echo</span><span>$strl</span>;</code>strstr(str,ch). str is the string to be retrieved, ch refers to the character to be retrieved, if set to true, the left character of the retrieved character will be returned. If not set, the character on the right is returned. The strchr() function returns the right character.
The above introduces the PHP string function (1), including aspects of the content. I hope it will be helpful to friends who are interested in PHP tutorials.