1
require_once('simple_html_dom.php'); 
require_once('url_to_absolute.php');
$html = file_get_html($GLOBALS["AL_CFG"]["siteURL"].'/articles/' . $PageData['ArticleID'] .'/print/');
foreach($html->find('img') as $element) {
// echo $element->src, "\n" . "<br>";
$MetaImage1 = $element->src;
$MetaImage = $MetaImage1;

Code above works fine - As results I get all the images on the page, altough : I would like to limit to the first one only. Thanks for your help.

(my php skills are very limited, please be specific. :)

1 Answer 1

1

1, use the second parameter of find (zero based):

$element = $html->find('img',0);
echo '<pre>',print_r($element),'</pre>';

or 2, break out of the foreach after 1 occurance:

foreach($html->find('img') as $element) {
    // echo $element->src, "\n" . "<br>";
    $MetaImage1 = $element->src;
    $MetaImage = $MetaImage1;
    break;
}
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.