Jump to content

Using PHP to get all of the anchor text elements in a navbar


p9142

Recommended Posts

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];
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.