0

我想删除此字符串中#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));
}

帮助

4

1 回答 1

0

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:

$array_bols = array("#bols", "#blitz", "#blitz ipva", "#ipva", "#detran", "#blitz de ipva", "#detran ipva", "#blitz d ipva");

foreach($array_bols as $blitz)
{
    if ($tmp = strstr($twit, $blitz)) {
        $twit = substr($tmp, strlen($blitz));
    }
}

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.

于 2011-05-07T23:56:52.510 回答