wrong parameter count for strstr()

懵懂的女人 提交于 2019-12-01 09:29:35
hakre

The PHP version you're using does not support the third parameter of strstrDocs, hence the error message. Your usage of the function requires PHP 5.3.0 or higher.

You can either upgrade the PHP version on your server or you replace the function call with something similar like:

substr($v->post_title, 0, strpos($v->post_title, ":"))

or if you want to use a helper function which is easier to read (Demo):

str_before($v->post_title, ":");

function str_before($subject, $needle)
{
    $p = strpos($subject, $needle);
    return substr($subject, 0, $p);
}

Related: strstr to show string before occurance

The third parameter was added in PHP 5.3.0. Is your running PHP version lower than 5.3.0?

substr($v->post_title, 0, strpos($v->post_title, ':'));

Will do the job on lower version of PHP.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!