duanniying2342 2014-08-04 22:57
浏览 33
已采纳

PHP简单的HTML DOM解析器不将alt标记显示为文本

 <?
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

  • 写回答

1条回答 默认 最新

  • dszpyf4859 2014-08-04 23:29
    关注

    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
    

    <kbd>Working code</kbd>

    Please check the <kbd>Manual</kbd> for more info...

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#java#的问题,请各位专家解答!
  • ¥15 急matlab编程仿真二阶震荡系统
  • ¥20 TEC-9的数据通路实验
  • ¥15 ue5 .3之前好好的现在只要是激活关卡就会崩溃
  • ¥50 MATLAB实现圆柱体容器内球形颗粒堆积
  • ¥15 python如何将动态的多个子列表,拼接后进行集合的交集
  • ¥20 vitis-ai量化基于pytorch框架下的yolov5模型
  • ¥15 如何实现H5在QQ平台上的二次分享卡片效果?
  • ¥30 求解达问题(有红包)
  • ¥15 请解包一个pak文件