how to get image source from an img tag using php function.
+3
A:
Consider taking a look at this.
I'm not sure if this is an accepted method of solving your problem, but check this code snippet out:
// Create DOM from URL or file
$html = file_get_html('http://www.google.com/');
// Find all images
foreach($html->find('img') as $element)
echo $element->src . '<br>';
// Find all links
foreach($html->find('a') as $element)
echo $element->href . '<br>';
ILMV
2010-01-18 09:38:23
+3
A:
You can use PHP Simple HTML DOM Parser (http://simplehtmldom.sourceforge.net/)
// Create DOM from URL or file
$html = file_get_html('http://www.google.com/');
// Find all images
foreach($html->find('img') as $element) {
echo $element->src.'<br>';
}
// Find all links
foreach($html->find('a') as $element) {
echo $element->href.'<br>';
}
marvin
2010-01-18 09:39:09
lol, "great minds think alike"...
ILMV
2010-01-18 09:40:05
and nearly at the same time
marvin
2010-01-18 09:41:01
+1
A:
Or, you can use the built-in DOM functions (if you use PHP 5+):
$doc = new DOMDocument();
$doc->loadHTMLFile($url);
$xpath = new DOMXpath($doc);
$imgs = $xpath->query("\\img");
for ($i=0; $i < $imgs->length; $i++) {
$img = $imgs->item($i);
$src = $img->getAttribute("src");
// do something with $src
}
This keeps you from having to use external classes.
Felix
2010-01-18 14:42:47