$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呢,也就是怎么总是执行一次呢?????????
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呢,也就是怎么总是执行一次呢?????????
while($index = strpos($content, '<IMG', $k))
{
++$aaa;
$j = strpos($content, '>', $right);
$k = $j - 3;
}
echo $aaa;exit;//怎么老是输出1呢,也就是怎么总是执行一次呢?????????
'<IMG' 在 $content 偏移0处就出现了,循环并不会进入
你第一次贴出来的($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次