Over a million developers have joined DZone.

HTML Parser - Grabs The Link URLs + Link Texts From A Web Page And Put Them Into An Array

·

\s*(.*?)";


  //global $q, $href1, $link_RE;
  preg_match_all("#$link_RE#i", $document, $matches);
  return $matches; // returns an array

} // end function parse_links()

//
// DEMO OF HOW TO USE THE FUNCTION

// grab a webpage
$str = implode('',file('http://del.icio.us'));

// call the parse_links function
$linkarray=parse_links($str);

// loop through the link array, outputting the URL + Link Text
for ($i = 0; $i < sizeof($linkarray[0]); $i++)
    echo ($linkarray[2][$i] .$linkarray[1][$i] . "
"); ?>
Topics:

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}