开发者

Replace all lines except first

I trying do something like that f开发者_JS百科or example:

<img src="/1.gif" />
<img src="/2.gif" />
<img src="/3.gif" />
<img src="/4.gif" />
<img src="/5.gif" />

And I want replace all lines contains IMG with "---" except first. I don't want delete it, just replace. I tried doing this with preg_replace but with no results.


There is no point in doing this with RegEx, you should use an XML parser like this one: http://php.net/manual/en/book.simplexml.php.

However, an even better approach in my oppinion is using client side technology for this. I would use jQuery because it's the one I know best, but any is just as good, even JavaScript outside of a framework.

For jQuery it would be something like:

$(document).ready(function()
{
   $('#parent-of-images-id img:not(first)').replaceWith('<p>---</p>');
});
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜