嗨,我需要做一个学校的任务,我需要从http://www.asaphshop.nl正则表达式的图像(和DomDoucument不工作,因为我得到多个错误。所以我需要用正则表达式。我现在唯一得到的是一个包含来自网站所有图片的长阵列,我只需要一张图片,这是我需要回显的代码部分(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>
这是我到目前为止的代码:
<?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);
?>
我建议使用HTML解析器这个任务 – Ghost 2014-10-31 08:13:48
'DomDoucument DOES不工作,因为我得到多个错误' – 2014-10-31 08:14:26
我已经看到过这种类型的问题。哦,那个问了三次以上的同一个问题的人。 – 2014-10-31 08:14:51