Nick
Nick

Reputation: 9373

Get SRC from div contents

I have code that gets a div contents:

include_once('simple_html_dom.php');
$html = file_get_html("link");
$ret = $html->find('div'); 

echo $ret[0];

preg_match_all('/(src)=("[^"]*")/i',$ret[0], $link);

echo $link[0];

It returns the full div contents including all the CSS. However I just wanted it to echo the information after src= basically just echoing the image link and nothing else. I've tried to use preg_match with no success.

Any ideas?

Upvotes: 0

Views: 188

Answers (2)

Pekka
Pekka

Reputation: 449415

Your HTML parser will help you there - there should be a src property in the $ret object:

echo $ret[0]->src;

Upvotes: 3

soju
soju

Reputation: 25312

You don't need regexp for that since you already use a dom parser.

foreach($ret as $element) 
       echo $element->src,'<br/>';

Upvotes: 1

Related Questions