简体   繁体   English

PHP简单的HTML DOM提取某些img

[英]Php simple html dom extracting certain img

Anyone with some knodledge of the PHP simple html dom parser? 有人对PHP简单html dom解析器有所了解吗? I´ve read the documentation at Php simple html dom parser 我已经阅读了Php简单html dom解析器中的文档

The thing im trying to do, is to find specific img urls that contains drupal-images on a page source. 我想做的事情是在页面源代码中找到包含drupal-images的特定img url。 for example: " http://drupal- images.tv2.dk/sites/images.tv2.dk/files/t2img/2016/02/22/480x270/227713601- 42562915-273368722d35758cde85a1320a6bb23b.jpeg" 例如:“ http:// drupal- images.tv2.dk/sites/images.tv2.dk/files/t2img/2016/02/22/480x270/227713601- 42562915-273368722d35758cde85a1320a6bb23b.jpeg”

and only find images which contains the word: drupal-images. 并且仅找到包含单词drupal-images的图像。 Is this possible?. 这可能吗?。

The only thing i´ve done so far, is to extract all images from a page, like this. 到目前为止,我唯一要做的就是像这样从页面中提取所有图像。

include("simplehtmldom_1_5/simple_html_dom.php");

$html = file_get_html("http://www.tv2.dk");
// Find all images
foreach($html->find('img') as $element)
echo $element->src . '<br>';

If you should find certain images with the .... would you use reqular expressions inside foreach? 如果您应该找到带有....的某些图像,您会在foreach中使用规则表达式吗?

And can I find the meta? 我可以找到该元吗? like this: meta name="Generator" content="Drupal 7 ( http://drupal.org ) 像这样:meta name =“ Generator” content =“ Drupal 7( http://drupal.org

I´ve searched a lot and it seems that i can only find with finding specific divs and classes. 我已经搜索了很多东西,似乎只有找到特定的div和类才能找到。

Thanks in advance. 提前致谢。

Simply strpos() can help you in that: 简单的strpos()可以帮助您:

    $str = 'drupal-images';
    $url = 'http://drupal-images.tv2.dk/sites/images.tv2.dk/files/t2img/2016/02/22/480x270/227713601-42562915-273368722d35758cde85a1320a6bb23b.jpeg';
    $urlArray = explode('/',$url);
    if(strpos($url, $str) > 0){
        $img = end($urlArray);
    }

I believe you can find how to use this example in your code. 我相信您可以在代码中找到如何使用此示例。

Regarfing meta data, you can use exif_read_meta() , more can be found here: http://php.net/manual/en/function.exif-read-data.php 添加元数据,您可以使用exif_read_meta() ,更多信息可以在这里找到: http : //php.net/manual/en/function.exif-read-data.php

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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