Strpos lookup Failure in PHP returns false considerations

Source: Internet
Author: User

Strpos usage

Strpos (String,find,start)

Let's look at a piece of code Strpos:

Ajax get participle
Public Function Get_segment_words () {
$title = I (' title ');
$content = I (' content ');
$Segment = M (' Segment ');
$Segment _content = M (' segment_content ');
$segment _array = $Segment->getfield (' Id,word ');
$setment _words = Array ();
foreach ($segment _array as $id => $word) {
if (False!== Strpos ($content, $word) | | false!== strpos ($title, $word)) {
$segment _words[] = $word;
}
}
$segment _words = Array_unique ($segment _words);
$segment _words = Implode (', ', $segment _words);
echo $segment _words;exit; Ajax Get Padding
}

Note This code:

if (False!== Strpos ($content, $word) | | false!== strpos ($title, $word)) {
Todo
}

If the match fails, STRPOS returns the bool type of false, which must be noted. What else would happen? If you want to match the character exactly in the first position, for Strpos this function is to return 0, that is, position 0. This time is actually a match, the result returns 0, if this is wrong to judge:

if (!strpos ($content, $word))

As an example:

Content: Shopping bag Vandersafara Dot van der Sar.

Matching: Shopping

If you want to find out whether there is "shopping" in the content of two words, Strpos will return 0, indicating the existence of "shopping" two words, the position is 0.

Therefore, the False!=strpos ($find, $content) is used to determine whether the match was successful.

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.