Home > Backend Development > PHP Tutorial > Strings with various pitfalls in php

Strings with various pitfalls in php

WBOY
Release: 2016-07-29 09:15:27
Original
1445 people have browsed it

1.strpos() function is used to find whether a certain substring exists in the target string. If it exists, it returns the position information of the substring, otherwise it returns false. When the position of the substring is at the beginning of the target string, the returned The position information is 0, so you need to use a constant judgment in the if statement, that is, if(strpos(...) === false), because 0==false is established in php; the same problem also occurs in strstr() function, the function returns the substring found for the first time and all characters before the substring. It can also return the substring and all characters after it by setting parameters (PS: the returned string contains substrings). When strstr(' 43210','0'), the function returns '0' == false, so when using the strstr function instead of strpos for determination, you must also pay attention to the identity principle, otherwise it may cause errors in judgment; if you only need to determine whether the substring exists, it is faster to use strpos.

2.

Copyright Statement: This article is an original article by the blogger and may not be reproduced without the blogger's permission.

The above has introduced the various pitfalls of PHP strings, including 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