Php 正则表达式的图像问题

Php 正则表达式的图像问题,php,html,image,Php,Html,Image,当我运行下面的脚本时,图像渲染不好。这里有什么问题?代码如下: <?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($u

当我运行下面的脚本时,图像渲染不好。这里有什么问题?代码如下:

<?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\>/isU";
    preg_match_all($pattern, $htmlcode, $matches);
    //print_r ($matches);
    $image = ($matches[0][0]);
    print_r ($image);
?>
这是我需要复制data-src-l部分的链接部分:

<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>
我希望你的女老师不要责骂你:

但最好将页面作为DOM结构处理,而不是作为字符串处理\\1是对[\']的反向引用,因此在字符串末尾使用相同的引号。对于URL来说没有必要,因为URL中不应该有不可替换的直接引用,但是对于一般用途来说这是很好的


ps:如果您需要它们之间的所有内容,包括-$pattern='class=noscript>**isU'

使用,不是regexp。这是我学校的作业。。。我需要用regexpTry完成这个类=\noscript\>.*data-src-l=[\']?.*\1.*isU。现在是输出:Array。。。空数组?!?修复了它,忘记了如何在PHP中注意到反向引用我使用了太多的语言-看这里仍然不工作,虽然。。。我需要完整的链接,比如:但是它只在重要的部分之后给出部分,它只显示:WebRoot/products/8020/80203122/bilder/80203122.jpg从数组中获取它并预处理您想要的内容有什么问题?你看到了吗http://asaphshop.nl 在感兴趣的部分的html代码中?不显然,它不会出现在regexp的结果中。但是我该如何解决这个问题呢?@bananaman获取regexp捕获的结果,将其分配给变量,并在所需主机名和协议$var='1'之前添加前缀http://asaphshop.nl' . $匹配[对应索引];
$dom = new DOMDocument();
$dom->loadHTMLFile('http://www.asaphshop.nl/epages/asaphnl.sf/nl_NL/?ObjectPath=/Shops/asaphnl/Products/80203122');

$xpath = new DOMXPath($dom);

$url = $xpath->query('//div[@id="ProductImages"]/ul/li/a/img/@data-src-l')->item(0)->nodeValue;

echo $url;
$pattern = "#class=\"noscript\">.*data-src-l=([\"'])(?<url>.*)\\1.*</div>#isU";