Search code examples
phpsrc

PHP get image src


$variable = '<img src="http://www.gravatar.com/avatar/66ce1f26a725b2e063d128457c20eda1?s=32&d=identicon&r=PG" height="32" width="32" alt=""/>';

How to get src of this image?

Like:

$src = 'http://www.gravatar.com/avatar/66ce1f26a725b2e063d128457c20eda1?s=32&d=identicon&r=PG';

Thanks.


Solution

  • You can use an html parser for this. See this one: http://simplehtmldom.sourceforge.net/ (I hope this works for nodes, not just for entire pages).