strpos总是返回相同的值

时间:2014-06-22 22:02:34

标签: php

在这两种情况下都会返回b

if(strpos('1', "Content-Length: 1 12327225") !== false) {
    echo 'a';
} else {
    echo 'b';
}

if(strpos('foqerwerun', "Content-Length: 1 12327225") !== false) {
    echo 'a';
} else {
    echo 'b';
}

有什么不对?

1 个答案:

答案 0 :(得分:3)

您错误地使用了strpos()。语法为strpos(string $haystack , mixed $needle [, int $offset = 0 ]).您要搜索的字符串位于第二个参数中,您搜索的字符串位于第一个参数中。

if(strpos("Content-Length: 1 12327225", '1') !== false) {
    echo 'a';
} else {
    echo 'b';
}

if(strpos("Content-Length: 1 12327225", '1') !== false) {
    echo 'a';
} else {
    echo 'b';
}
相关问题