关于 substr() 的帮助
我想删除该字符串中 #blitz 之前的所有内容:
$twit = rt @danisan01: #blitz ipva em frente ao barra sul, no recreio.
这是我正在尝试的内容,但在输出中没有得到任何结果:
$array_bols = array("#bols", "#blitz", "#blitz ipva", "#ipva", "#detran", "#blitz de ipva", "#detran ipva", "#blitz d ipva");
foreach($array_bols as $blitz)
{
$twit = substr(strstr($twit, $blitz), strlen($blitz), (-1) * strlen($twit));
}
help
I want to remove everything before #blitz in this string:
$twit = rt @danisan01: #blitz ipva em frente ao barra sul, no recreio.
here's what I'm trying but I get no results on the output:
$array_bols = array("#bols", "#blitz", "#blitz ipva", "#ipva", "#detran", "#blitz de ipva", "#detran ipva", "#blitz d ipva");
foreach($array_bols as $blitz)
{
$twit = substr(strstr($twit, $blitz), strlen($blitz), (-1) * strlen($twit));
}
help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不会得到任何输出,因为您迭代了搜索词列表。并且您的 $twit 变量将在某个时候被清空,因为如果
strstr
找不到搜索的主题,则不会返回任何内容。您想要做的如下:
内部 substr 还删除了
#blitz
因为我认为这就是您的代码的用途。请注意在这种情况下如何省略 substr() 长度参数。You get no output, because you iterate over a list of search words. And your $twit variable will be emptied at some point, because
strstr
returns nothing if it can't find the searched subject.What you wanted to do is following:
The inner substr also removes the
#blitz
as I assume that's what your code was for. Note how you can leave out the substr() length parameter in such cases.