0

I have the following:

$input = '<p>This is a sample of a content I am working with <br /> Check out this image <img src="http://mydomain.com/1.png" /> or this one <img src="http://mydomain.com/2.png" />';

How can I get this two urls in an array?

['<img src="http://mydomain.com/1.png" />','<img src="http://mydomain.com/2.png" /'>]
James Wiseman
  • 29,946
  • 17
  • 95
  • 158
Toni Michel Caubet
  • 19,333
  • 56
  • 202
  • 378

4 Answers4

3

To parse HTML it is recommanded to use PHP's DOMDOCUMENT, as stated here: Parse HTML with PHP's HTML DOMDocument

$dom = new DOMDocument();
$dom->loadHTML($input);

foreach($dom->getElementsByTagName('img') as $img) {
        echo $img->getAttribute('src') . "<br />\r\n";
    } 
Community
  • 1
  • 1
Bgi
  • 2,513
  • 13
  • 12
0

This will probably helps you : http://php.net/manual/en/function.preg-match.php

Itsmeromka
  • 3,621
  • 9
  • 46
  • 79
0

I think this function will be more suitable for your purpose: http://www.php.net/manual/en/function.preg-replace-callback.php

Ariaan
  • 1,105
  • 1
  • 9
  • 13
0

Simple! Check HTMLSQL

With HTMLSQL you can filter all html tags.

Eugen
  • 1,356
  • 12
  • 15