Simple question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jackmn1
Forum Newbie
Posts: 9
Joined: Thu Jul 01, 2010 4:49 am

Simple question

Post 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
jackmn1
Forum Newbie
Posts: 9
Joined: Thu Jul 01, 2010 4:49 am

Re: Simple question

Post 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.
User avatar
Apollo
Forum Regular
Posts: 794
Joined: Wed Apr 30, 2008 2:34 am

Re: Simple question

Post by Apollo »

Code: Select all

$s = preg_replace('/(<img [^>]+>)/','<li>\1</li>',$s);
jackmn1
Forum Newbie
Posts: 9
Joined: Thu Jul 01, 2010 4:49 am

Re: Simple question

Post by jackmn1 »

Great! thanks a lot, Apollo.
Post Reply