-1

In the following example, my array returns empty. I need to get the (complete!) image link into my array.

This is my code:

<?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);
?>

This is the part of the file I am using to try and get the (complete!) image link into my array:

 <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>
misterManSam
  • 24,303
  • 11
  • 69
  • 89
bananaman
  • 31
  • 2
  • 9

1 Answers1

0

First : you should never parse HTML with a regex, as HTML is too complex to be parsed like that. Have a look on this post.

For your question, your problem is that you're using multiline modifier instead of the singleline one. Change your regex for this one :

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

And if you want a cleanest result, use this one (with lookbehind/lookahead):

/(?<=class=\"noscript\"\>)(.*?)(?=\<\/div\>)/isU
Community
  • 1
  • 1
zessx
  • 68,042
  • 28
  • 135
  • 158
  • thanks but now my array is still not good, this is the link now: http://localhost/WebRoot/products/8020/80203122/bilder/80203122.jpg but it needs to get out of the localhost, something like: http://www.asaphshop.nl/WebRoot/products/8020/80203122/bilder/80203122.jpg how do i do this? – bananaman Oct 16 '14 at 10:17
  • This is another problem. You should replace every occurence of `src="/` by `src="http://www.asaphshop.nl/` . Same for , `data-src-xs="/`, `href="/`... – zessx Oct 16 '14 at 10:31