$content = '<IMG src="http://pub.chushan.com/images/home/smilies/1.gif width="200" height="200"><IMG src="http://pub.chushan.com/images/home/smilies/1.gif width="200" height="200">';                  $k = $aaa = 0;
while($index = strpos($content, '<IMG', $k))
{
                           ++$aaa;
$i    = strpos($content, 'src', $index);
$left  = strpos($content, 'http', $i);
$right = strpos($content, 'gif', $left);
$url   = substr($content, $left, $right + 3 - $left);
$replace = '<IMG src="'.$url.'">';
$j = strpos($content, '>', $right);
$search = substr($content, $index, $j + 1 - $index);
$content = str_replace($search, $replace, $content);
$k = $index + strlen($replace) - 3;
}echo $aaa;exit;//怎么老是输出1呢,也就是怎么总是执行一次呢?????????

解决方案 »

  1.   

    简化一下:$content = '<IMG src="http://pub.chushan.com/images/home/smilies/1.gif width="200" height="200"><IMG src="http://pub.chushan.com/images/home/smilies/1.gif width="200" height="200">';$k = $aaa = 0;
    while($index = strpos($content, '<IMG', $k))
    {
        ++$aaa;
        $j = strpos($content, '>', $right);
        $k = $j - 3;
    }
    echo $aaa;exit;//怎么老是输出1呢,也就是怎么总是执行一次呢?????????
      

  2.   

    不可能吧?你能输出 1 吗?
    '<IMG' 在 $content 偏移0处就出现了,循环并不会进入
      

  3.   

    开始的那块我是$content = 'a'.$content;的
      

  4.   

    这个费劲,.... 貌似用正则就可以了....或者用DOM也要清楚很多....调试的话,循环里把$content, $k等几个值echo一下就查出来原因了,
      

  5.   

    你是不是想查<img出现的次数
    你第一次贴出来的($content = 'a<IMG src="http://pub.chushan.com/images/home/smilies/1.gif width="200" height="200"><IMG src="http://pub.chushan.com/images/home/smilies/1.gif width="200" height="200">';)是2次
      

  6.   

    我想将<img>标签进行替换,不过弄出来了,谢谢各位了