Php string pregnancy comparison replacement

Source: Internet
Author: User
Php string contains comparison replacement if (strpos ($ str ,?? 'OK ')! = False ){??? // Include }?? // Error method ?? If (strpos ($ str ,?? 'OK ')){...??} To determine whether the string $ str contains the 'OK' php string.

If (strpos ($ str ,?? 'OK ')! = False ){?

?? // Contains

}

?

?

// Incorrect method

?

?

If (strpos ($ str ,?? 'OK ')){...??}

To determine whether the string $ str contains 'OK', but recently it was found that a string with 'OK' was not found successfully. Sadly, this string starts with 'OK'. how can it not be found?
Find the strpos function definition, and srtpos returns the first position of the string that appears. this position starts from 0, for example, in 'It' s OK! ', The location of' OK 'is 5. If no value is found, false is returned. Found the problem: PHP variable types are weak and can be converted to variable types at will. 0 can be regarded as an integer or Boolean false, add strpos to determine whether the position of the string to be searched appears at 0. the function returns 0. is the if statement regarded as 0 or false? It seems that this is the problem.
Find the problem and the solution is available. add one character before the searched string.Not included inThe character in the keyword is enough, so as long as it is matched, the returned result will always be greater than or equal to 1.

?

?

?

?

 
?

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.