搜索另一个字符串中是否存在字符串

Mal*_*loc 5 php

为了我的目的,我这样做了:

<?php
$mystring = 'Gazole,';
$findme   = 'Sans Plomb 95';
$pos = strpos($mystring, $findme);

if ($pos >= 0) {
    echo "The string '$findme' was found in the string '$mystring'";
    echo " and exists at position $pos";
} else {
    echo "The string '$findme' was not found in the string '$mystring'";
}
?>
Run Code Online (Sandbox Code Playgroud)

但是,它总是执行此分支:

echo "The string '$findme' was found in the string '$mystring'";
echo " and exists at position $pos";
Run Code Online (Sandbox Code Playgroud)

虽然我正在搜索的字符串不存在.

请提前帮助:)

Jon*_*Jon 14

正确的方法是:

if ($pos !== false) {
    echo "The string '$findme' was found in the string '$mystring'";
    echo " and exists at position $pos";
} else {
    echo "The string '$findme' was not found in the string '$mystring'";
}
Run Code Online (Sandbox Code Playgroud)

请参阅文档中的巨型红色警告.