PHP - strstr函数问题

zoz*_*ozo 1 php zend-framework strstr

大家好日子.我正在使用zend + smarty,但我不认为该框架与该问题有任何关系.我有以下场景:

     A script that gets a string from a specified site using an api. The string is retrieved corectly so I'll just assign a string to a variable:

     $string = 'String retrieved from api.';
     $string = strstr($string, "<?xml", false);

     libxml_use_internal_errors(true);
     $xml = simplexml_load_string($body);
Run Code Online (Sandbox Code Playgroud)

听起来不错,看起来不错.现在问题.

当我在我们的本地测试机器上使用它时,它就像一个梦想.没问题.另一方面,在生产机器上我得到了这个:

警告:第720行/home/prj/include/DatabaseObject/Ctrl.php中的strstr()参数计数错误(这是strstr行).

我在两台机器上的strstr之前检查了字符串,它们是相同的.同样在strstr行之后的第二个服务器上,字符串变为空(在另一个服务器上,它被正确转换).

我真的不明白......代码是一样的.字符串是相同的.对我来说有点奇怪.

Eri*_*rik 5

在php 5.3中添加了第三个参数"before needle" - 一个布尔值.您的生产服务器可能正在运行早期版本.

PHP.net

strstr ( string $haystack , mixed $needle [, bool $before_needle = false ] )

  • 5.3.0添加了可选参数before_needle.