Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/269.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
php字符串如何在一个数字字符串中找到一个数字_Php - Fatal编程技术网

php字符串如何在一个数字字符串中找到一个数字

php字符串如何在一个数字字符串中找到一个数字,php,Php,可能重复: 我希望有一些PHP代码来检查某个数字是否出现在一个数字字符串中,例如,我如何检查数字7是否出现在数字3275中 我试过strcmp,但我不能解决这个问题:看看;您可以使用它来查找子字符串在字符串中出现的位置,并进一步确定它是否出现。有关如何正确执行检查,请参见第一个示例 if(stristr('3275', '7') !== false) { // found } 查找haystack字符串中第一个出现的指针的数字位置 确保使用!==比较返回值以查看其是否存在时为false否

可能重复:

我希望有一些PHP代码来检查某个数字是否出现在一个数字字符串中,例如,我如何检查数字7是否出现在数字3275中

我试过strcmp,但我不能解决这个问题:

看看;您可以使用它来查找子字符串在字符串中出现的位置,并进一步确定它是否出现。有关如何正确执行检查,请参见第一个示例

if(stristr('3275', '7') !== false)
{
  // found
}
查找haystack字符串中第一个出现的指针的数字位置

确保使用!==比较返回值以查看其是否存在时为false否则7325将返回位置0和0==false-==and!==比较值和类型是布尔值还是整数

请尝试以下代码:

$pos = strrpos($mystring, "7");
if ($pos === false) { // note: three equal signs
    // not found...
}
else{
    //string found
}

是你的朋友,PHP不是强类型的,所以你可以把数字当作字符串。

$mystring = 3232327;
$findme   = 7;
$pos = strpos($mystring, $findme);

if ($pos === false) {
    echo "The number '$findme' was not found in the number '$mystring'";
} else {
    echo "The number '$findme' was found in the number '$mystring'";
    echo " and exists at position $pos";
}
像这样试试

$phno = 1234567890;
$collect = 4;
$position = strpos($phno, $collect);

if ($position)
    echo 'The number is found at the position'.$position;   
else
    echo 'Sorry the number is not found...!!!';

ifstristr3275,7!==false{//found}注意,“strrpos”查找最后一次出现,而“strpos”查找第一次出现。这两个函数都适用于此用例。
$phno = 1234567890;
$collect = 4;
$position = strpos($phno, $collect);

if ($position)
    echo 'The number is found at the position'.$position;   
else
    echo 'Sorry the number is not found...!!!';