php string function (1)

WBOY
Release: 2016-08-08 09:24:20
Original
1101 people have browsed it

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>
Copy after login
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


3. Retrieve string function/strstr() function and strchr() 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>
Copy after login
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.


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template