开发者

How to ignore first match in this regex

$tag开发者_运维技巧 = 'img';
$text = preg_replace('#</?'.$tag.'[^>]*>#is', '', $text);

how can I make preg_replace ignore the first match ("img"), and do the replacing just on the others?


you can use a for() loop and set $i as 1 to avoid the first value in the array, so something like :

 for($i = 1; $tags < count($tags) ; $i++){
 $text = preg_replace('#</?'.$tag.'[^>]*>#is', '', $text[$i]);
 }

but this loop will replace $text value everytime its executed, if you want to save it as a string replace the = sign with .= or if you want to make an array replace $text with $text[$i--]

note that this code is not tested!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜