p9142 Posted February 5, 2009 Share Posted February 5, 2009 I am new to PHP, and I am trying to search through an unordered list and grab each of the anchor text elements. I am using this code, but it only returns the first anchor text element, "Link1" Is there a way to expand this code so that I can find all the link elements in my unordered list? Many thanks in advance. <?php $links = '<ul><li><a href="http://www.blahblah1.com">Link1</a></li> <li><a href="http://www.blahblah2.com">Link2</a></li> <li><a href="http://www.blahblah3.com">Link3</a></li> <li><a href="http://www.blahblah4.com">Link4</a></li> </ul>'; $matchstring = "/\"\>(.+)\<\/a/"; preg_match ($matchstring, $links, $match); echo $match[1]; ?> Link to comment https://forums.phpfreaks.com/topic/143974-using-php-to-get-all-of-the-anchor-text-elements-in-a-navbar/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.