PHP - 什么警告:strpos()[function.strpos]:空分隔符是什么意思?

时间:2010-11-05 10:31:39

标签: php

警告:strpos()[function.strpos]:空分隔符是什么意思?

我有这个:

    if(strpos(''', $text) === false)
    {
        $text = str_replace(''', "'", $text);
    }

4 个答案:

答案 0 :(得分:4)

猜测一下,我会说$text是一个空字符串(感谢Mark指出具体细节)

编辑:另外,另一个猜测是您的参数顺序错误。 strpos的方法签名是

int strpos ( string $haystack , mixed $needle [, int $offset = 0 ] )

请参阅http://php.net/manual/en/function.strpos.php

答案 1 :(得分:1)

对于初学者来说,你错了......

  • strpos可能会返回false""0
  • 第一个参数必须是hastack
  • 第二个论点应该是针。

你应该做的是:

if(false !== ($position = strpos($text,'''))) //Position Found and set in $position
{
    //$position holds the offset to the needle.
    $text = str_replace(''', "'", $text);
}

petones

答案 2 :(得分:1)

在变量$Text

上尝试添加双引号

更改:if(strpos(''', $text)

进入:if(strpos(''', ".$text.")

if(strpos(''', ".$text.") === false)
    {
        $text = str_replace(''', "'", $text);
    }

答案 3 :(得分:1)

删除后我遇到了这个错误?>从WP的主题function.php结束,但错误仅报告一次。