Search code examples
phppreg-replacestrip

preg_replace everything before the first and after the second double quotes


Can't find anything that works. Need to remove everything before the first and after the second doulble quotes:

Example:

<a href="http://somesite.com"><img src="http://somesite.com/image.png"></a>

The result should be:

http://somesite.com

Thank you very much!

SOLVED: see @ankabout 's solution.


Solution

  • $html = '<a href="http://somesite.com"><img src="http://somesite.com/image.png"></a>';
    $dom = new DOMDocument();
    $dom->loadHTML($html);
    var_dump($dom->getElementsByTagName('a')[0]->getAttribute('href'));