数组返回空

香蕉人

在下面的示例中,我的数组返回空。我需要将(完整!)图像链接放入我的数组中。

这是我的代码:

<?php
    header('Content-Type: text/html; charset=utf-8');
    $url = "http://www.asaphshop.nl/epages/asaphnl.sf/nl_NL/?ObjectPath=/Shops/asaphnl/Products/80203122";
    $htmlcode = file_get_contents($url);
    $pattern = "/class=\"noscript\"\>(.*?)\<\/div\>/imU";
    preg_match_all($pattern, $htmlcode, $matches);
    //print_r ($matches);
    $image = ($matches[0]);
    print_r ($image);
?>

这是我用来尝试将(完整!)图像链接放入我的数组的文件的一部分:

 <div id="ProductImages" class="noscript">
    <ul>
      <li>
        <a href="/WebRoot/products/8020/80203122/bilder/80203122.jpg">
          <img
           itemprop="image"
           alt="Jesus Remember Me - Taize Songs (2CD)"
           src="/WebRoot/AsaphNL/Shops/asaphnl/5422/8F43/62EE/D698/EF8E/4DEB/AED5/3B0E/80203122_xs.jpg"
           data-src-xs="/WebRoot/AsaphNL/Shops/asaphnl/5422/8F43/62EE/D698/EF8E/4DEB/AED5/3B0E/80203122_xs.jpg"
           data-src-s="/WebRoot/products/8020/80203122/bilder/80203122_s.jpg"
           data-src-m="/WebRoot/products/8020/80203122/bilder/80203122_m.jpg" 
           data-src-l="/WebRoot/products/8020/80203122/bilder/80203122.jpg"
         />
        </a>
      </li>
    </ul>
  </div>
泽斯

首先:永远不要使用正则表达式来解析HTML,因为HTML太复杂了,无法像这样进行解析。看一下这个帖子

对于您的问题,您的问题是您使用的是多行修饰符而不是单行修饰符。更改此正则表达式:

/class=\"noscript\"\>(.*?)\<\/div\>/isU

如果您想要最干净的结果,请使用此结果(后向/向前看):

/(?<=class=\"noscript\"\>)(.*?)(?=\<\/div\>)/isU

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章