【问题标题】:Filtering images fetched from url by HTML DOM Parsing通过 HTML DOM Parsing 过滤从 url 获取的图像
【发布时间】:2012-01-30 14:34:49
【问题描述】:

我正在像这样通过 HTML DOM 从 url 中获取所有图像

foreach($html->find('img') as $element)
{
  $gimages .= '<img src="';
  $gimages .= $element->src;
  $gimages .= '"width="100"';
  $gimages .= $k;
  $gimages .= '">';
}

我通过上面的代码获取所有图像。但我想过滤我可以在我的网络中显示的确切图像。喜欢 http://l.yimg.com/eur.yimg.com/i/any/rebel19.jpg 但有时我会得到无效的路径。如何检查有效的图像路径。

【问题讨论】:

    标签: php html dom html-parsing


    【解决方案1】:

    使用这个

    $handle = fopen("http://l.yimg.com/eur.yimg.com/i/any/rebel19.jpg", "r");
    
    if (!$handle) {
      // file is not present
    } else {
      // file present
      // do operation u wnted
    }
    
    fclose($handle);
    

    这将帮助您检查该文件是否存在于该位置

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-20
      • 2011-09-25
      • 2012-10-17
      • 1970-01-01
      • 2014-06-08
      • 2012-04-16
      相关资源
      最近更新 更多