Page 1 of 1

Simple question

Posted: Thu Jul 01, 2010 4:55 am
by jackmn1
Hello,

How can I wrap img tags with li tags?
I have a bunch of images such as

Code: Select all

<img src="a.jpg"><img src="b.jpg"><img src="c.jpg">
.
I would like to wrap each of them with li tag. Can you please tell me how to do this?

Thanks

Re: Simple question

Posted: Thu Jul 01, 2010 6:56 am
by jackmn1
Just to clarify, I'm talking about an unknown number of images, and the list should be generated with PHP and not HTML.
The user (who doesn't know HTML), will add images through the CMS GUI, and then the PHP should grab each image and wrap it with li tag.

Re: Simple question

Posted: Thu Jul 01, 2010 7:05 am
by Apollo

Code: Select all

$s = preg_replace('/(<img [^>]+>)/','<li>\1</li>',$s);

Re: Simple question

Posted: Thu Jul 01, 2010 7:12 am
by jackmn1
Great! thanks a lot, Apollo.