0

Okey, the table row contains this:

<ul>
    <li>
        <img>
    </li>
    <li>
        <img>
    </li>
</ul>

And I need to only get the images out, and theres no other way to retreive these files. I know, its a stupid input. But is there a way to get only the img-tag out?

Abbas
  • 14,186
  • 6
  • 41
  • 72
Marius Djerv
  • 267
  • 1
  • 4
  • 18

3 Answers3

0

I assume this piece of HTML is in one variable and you want to "parse" the result? If so, you could use something like:

preg_match_all('/<img.+?src="(.+)"/', $html, $matches);

In matches you will find the sources (or entire image tags).

Ronald Swets
  • 1,669
  • 10
  • 16
0

You can use strip_tags() to get the specific one or more tags

Syntax:

string strip_tags ( string $str [, string $allowable_tags ] )

Code:

 $text ="<ul>
    <li>
      <img>
    </li>
    <li>
      <img>
    </li>
</ul>";

  echo strip_tags($text, '<img>');

Ref: http://www.php.net/strip_tags

Krish R
  • 22,583
  • 7
  • 50
  • 59
0

This can be done using regex but thats not a good solution for this,

Use this instead:

echo strip_tags($html, '<img>');

Note: $html contains all the html you want to parse

Qarib Haider
  • 4,796
  • 5
  • 27
  • 38