-1

i'd like to get more than one result using the fuction mentioned in the title, so far i'm just able to get just an only value using preg_match. I'd like to get an array of all the results and then record them in my db.

That's my current code:

$casturl = "https://www.themoviedb.org/movie/353491-the-dark-tower/cast";
$cast = file_get_contents($casturl);
preg_match_all('|<img class="profile lazyload fade" data-sizes="auto" data-src="(.*?)" data-srcset="|' , $cast , $castimg );    
print_r($castimg);

When i print the results i'm just giving: Array ( [0] => Array ( [0] =>

I made sure cast contains what i want. I've tried already a lot of possibilities and i got nothing :(

  • You *are* getting your results, but it's printing HTML so it gets messed up. Try using `var_dump($castimg);` and you'll see. – ishegg Sep 22 '17 at 19:46
  • Please read [Under what circumstances may I add “urgent” or other similar phrases to my question, in order to obtain faster answers?](//meta.stackoverflow.com/q/326569) - the summary is that this is not an ideal way to address volunteers, and is probably counterproductive to obtaining answers. Please refrain from adding this to your questions. – halfer Sep 23 '17 at 16:32

2 Answers2

0

Try this one. I hope you grabbing all image URL's

$casturl = "https://www.themoviedb.org/movie/353491-the-dark-tower/cast";
$cast = file_get_contents($casturl);
preg_match_all('#<img class="profile lazyload fade" data-sizes="auto" data-src="(.*?)" data-srcset="#' , $cast , $castimg );    
print_r($castimg[1]);

Output

Array ( [0] => https://image.tmdb.org/t/p/w66_and_h66_bestv2/d9NkfCwczP0TjgrjpF94jF67SK8.jpg [1] => https://image.tmdb.org/t/p/w66_and_h66_bestv2/jdRmHrG0TWXGhs4tO6TJNSoL25T.jpg [2] => https://image.tmdb.org/t/p/w66_and_h66_bestv2/gzjmHOSM1vnwnXpU737tdu9YjOu.jpg [3] => https://image.tmdb.org/t/p/w66_and_h66_bestv2/zYiS1KJKEoLstzFA3DV5gwszzSC.jpg [4] => https://image.tmdb.org/t/p/w66_and_h66_bestv2/vDuvdRoliXbjQrptk7GVs4Qj07S.jpg ......)
RamaKrishna
  • 219
  • 1
  • 8
-1

If you use

var_dump($castimg);

instead

print_r($castimg);

you will see much more clear.

Daniel
  • 132
  • 1
  • 2
  • 10