Php 正则表达式图像问题

Php 正则表达式图像问题,php,regex,Php,Regex,嗨,我需要为学校做一个作业,在那里我需要从那里得到一个带有正则表达式的图像,而domdocument不起作用,因为我有多个错误。所以我需要用正则表达式。我现在得到的唯一东西是一个长数组,里面有来自该站点的所有图片。我只需要一张图片。这是我需要回显的代码src lof的数据部分: <div id="ProductImages" class="noscript"> <ul> <li> <a href="/WebRoot/

嗨,我需要为学校做一个作业,在那里我需要从那里得到一个带有正则表达式的图像,而domdocument不起作用,因为我有多个错误。所以我需要用正则表达式。我现在得到的唯一东西是一个长数组,里面有来自该站点的所有图片。我只需要一张图片。这是我需要回显的代码src lof的数据部分:

<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>
这是我目前的代码:

<?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 = "/<img\s[^>]*?src\s*=\s*['\"]([^'\"]*?)['\"][^>]*?>/";
preg_match_all($pattern, $htmlcode, $matches);
//print_r ($matches);
$image = ($matches[0]);
$image = str_replace('src="/', 'src="http://www.asaphshop.nl/', $image);
print_r ($image);
?>

我不明白这个问题。你的问题在哪里。。。 您只是尝试使用data-src-l图像url

更改代码:

$pattern = "/<img\s[^>]*?src\s*=\s*['\"]([^'\"]*?)['\"][^>]*?>/";
$image = ($matches[0]);
$image = str_replace('src="/', 'src="http://www.asaphshop.nl/', $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($url);
$pattern = '/<img\s[^>]*?data-src-l="([^"]+)[^>]*?>/';
preg_match($pattern, $htmlcode, $matches);
$imageLink = "http://www.asaphshop.nl". $matches[1];
$image = '<img src="'. $imageLink .'">';
print_r ($image);
?>

我建议对此任务使用HTML解析器DOMDOUNT不起作用,因为我遇到了多个错误我以前已经看到过这种类型的问题。哦,就是那个问同一个问题三次以上的人。@Ghost我明白,但我需要和他一起做regex@AvinashRaj我找不到,你最好帮帮我;我现在得到的是:nothingParse错误:语法错误,在第5行的C:\xampp\htdocs\stage\ripper2.php中出现意外错误是的,对不起,这只是一个字符串php问题。好的!我们快到了!它现在是链接,但它应该是它自己的图像。像那样吗?我改变结局
<?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 = '/<img\s[^>]*?data-src-l="([^"]+)[^>]*?>/';
preg_match($pattern, $htmlcode, $matches);
$imageLink = "http://www.asaphshop.nl". $matches[1];
$image = '<img src="'. $imageLink .'">';
print_r ($image);
?>
$url = "http://www.asaphshop.nl/epages/asaphnl.sf/nl_NL/?ObjectPath=/Shops/asaphnl/Products/80203122";
$htmlcode = file_get_contents($url);
preg_match('/data-src-l="(.*)"/',$htmlcode ,$matches);
$image = ($matches[1]);
$path= 'http://www.asaphshop.nl'.$image;