jackmn1 Posted July 1, 2010 Share Posted July 1, 2010 Hello, How can I wrap img tags with li tags? I have a bunch of images such as <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 Quote Link to comment https://forums.phpfreaks.com/topic/206373-simple-question/ Share on other sites More sharing options...
trq Posted July 1, 2010 Share Posted July 1, 2010 <li><img src="a.jpg"></li><li><img src="b.jpg"></li><li><img src="c.jpg"></li> Quote Link to comment https://forums.phpfreaks.com/topic/206373-simple-question/#findComment-1079617 Share on other sites More sharing options...
jackmn1 Posted July 1, 2010 Author Share Posted July 1, 2010 Thanks but that's not what I meant. I was refering to php dynamic code and not HTML. The number of images is unknown and I need to wrap each of them with LI tags (probably using regex?) Quote Link to comment https://forums.phpfreaks.com/topic/206373-simple-question/#findComment-1079658 Share on other sites More sharing options...
trq Posted July 1, 2010 Share Posted July 1, 2010 Where are these image tags coming from? Quote Link to comment https://forums.phpfreaks.com/topic/206373-simple-question/#findComment-1079660 Share on other sites More sharing options...
jackmn1 Posted July 1, 2010 Author Share Posted July 1, 2010 The images will be included in a regular post in a wordpress blog. I would like the blog owner to be able to enter the images to a post without dealing with the HTML ( they will add them via the visual editor/GUI). Afterwords, I need the PHP to grab each image from the content of that post and wrap it with an li tag so it can be viewed as image gallery (horizontal scroller) using some Jquery plugin that I have. I know there are plugins for WP that can do this but I would rather not use the plugin and have my own customized code instead. Quote Link to comment https://forums.phpfreaks.com/topic/206373-simple-question/#findComment-1079666 Share on other sites More sharing options...
trq Posted July 1, 2010 Share Posted July 1, 2010 In that case, its probably easiest to do this in jQuery. wrapInner will do the trick easily. Quote Link to comment https://forums.phpfreaks.com/topic/206373-simple-question/#findComment-1079670 Share on other sites More sharing options...
trq Posted July 1, 2010 Share Posted July 1, 2010 Sorry, wrap was what your after. Quote Link to comment https://forums.phpfreaks.com/topic/206373-simple-question/#findComment-1079671 Share on other sites More sharing options...
jackmn1 Posted July 1, 2010 Author Share Posted July 1, 2010 Thank you thorpe. Just in case anyone is interested I have the answer in PHP: $content = preg_replace('/(<img [^>]+>)/','<li>\1</li>',$content ); Quote Link to comment https://forums.phpfreaks.com/topic/206373-simple-question/#findComment-1079673 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.