strstr()的参数计数错误 [英] wrong parameter count for strstr()

查看:99
本文介绍了strstr()的参数计数错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用帖子GUID在wordpres中构建了一个导航菜单,并且发布了标题,我只使用了部分标题,为此,我将执行以下操作,

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,

$casestudylist .= "<li class='subnav'><a href=".$v->guid.">". strstr($v->post_title, ":", true)."</a></li>";

但是我收到以下警告,但无法找出原因:

however I get the following warning and cannot work out why:

wrong parameter count for strstr()

基本上,我试图将所有字符从字符串中拉出,如果它们在:之前.

Basically I am trying to pull all the characters out of a string if they are before a :.

推荐答案

您使用的PHP版本不支持

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.

您可以在服务器上升级PHP版本,也可以将函数调用替换为类似的内容:

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);
}

相关: strstr在出现之前显示字符串

这篇关于strstr()的参数计数错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆