php - image link problems regular expressions -
when run next script, image not rendered well. problem here? code (it's assignment school , need regular expressions...):
<?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); ?>
this part of link need re-create (the data-src-l part)with link of http://www.asaphshop.nl in front end of have (complete) link of 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>
with pattern data-src-l="(.*)"
should do
see demo here
the regex matching literarly data-src-l="
, capturing (.*)
until lastly double quote "
a improve match [^"]*
instead of .*
capture "
([]
class of character, starting ^
invert (all next chars) , "
represent not wanted.
on demo can play , see explanation on right panel.
php regex
No comments:
Post a Comment