简体   繁体   中英

PHP Simple HTML DOM Parser not displaying alt tag as text

 <?
include('simple_html_dom.php');
// Create DOM from URL or file
$html = file_get_html('http://www.saie.bolognafiere.it/it/partner/media-partner');

// Find all images 
foreach($html->getAttribute('ul#slider356 alt') as $element) 
       echo $element->plaintext . '<br>';
?>

Actually I would like that all the alt tag content contained in the " ul id="slider356 " are displayed as text but my code is not working can someone help me ?

Thank you

To complete Sean's comment, there is two ways to get the attribute's value:

  1. $node->attribute;
  2. $node->getAttribute('attribute');

So, in your case, try this:

$html = file_get_html('http://www.saie.bolognafiere.it/it/partner/media-partner');

// Find all images inside ul#slider356
foreach($html->find('ul#slider356 img') as $element)
    // Print alt value
    echo $element->alt . "<br/>";
    // $element->getAttribute('alt') should work as well

Working code

Please check the Manual for more info...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM