wrong parameter count for strstr()

前端 未结 3 1367

I have built a nav menu in wordpres using a posts GUID, and post title, I am taking only part of the title and to do this I am doing the following,

$casestu         


        
相关标签:
3条回答
  • 2021-01-14 09:20
    substr($v->post_title, 0, strpos($v->post_title, ':'));
    

    Will do the job on lower version of PHP.

    0 讨论(0)
  • 2021-01-14 09:37

    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

    0 讨论(0)
  • 2021-01-14 09:38

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

    0 讨论(0)
提交回复
热议问题