0

file contains :

   <a href="site.com/" h="
   <a href="site3.com/" h="

so i want to echo all urls via pattern with preg_grep or preg_match ?

a pattern to get all between href=" and "

thanks !

HolaKo
  • 3
  • 4

1 Answers1

0

Here's an example how to use DOMDocument

$html = '
    <a href="site.com/">link1</a>
    <a href="site3.com/">link2</a>
';


$dom = new DOMDocument();
$dom->loadHTML($html);
$links = $dom->getElementsByTagName('a');

foreach($links as $link) {
    echo $link->getAttribute('href');
}

Look at another example at php.net

bitWorking
  • 12,485
  • 1
  • 32
  • 38