Jump to content

My little Grabber


selenin

Recommended Posts

Hello, the ultra beginner is back and I try to write a little grabber, that's what I did

 

<?
$url  = "http://www.novamov.com/search.php?q=Alice+in+wonderland&submit=";
$data = file_get_contents($url);
$searchterm = 'Alice in Wonderland';

preg_match_all('/<a href[^>]*>'.$searchterm.'/i', $data, $match);

var_dump($match);

?>

 

and that's what I got source code:

 

array(1) {

  [0]=>

  array(6) {

    [0]=>

    string(72) "<a href="http://www.novamov.com/video/dfre8qs9n4yas">Alice in Wonderland"

    [1]=>

    string(72) "<a href="http://www.novamov.com/video/4bf1ddd90a2c1">Alice in Wonderland"

    [2]=>

    string(72) "<a href="http://www.novamov.com/video/5sixh4i7ip226">Alice in Wonderland"

    [3]=>

    string(72) "<a href="http://www.novamov.com/video/4beddd60cba4e">Alice in wonderland"

    [4]=>

    string(72) "<a href="http://www.novamov.com/video/dqktchzlsikpa">Alice In Wonderland"

    [5]=>

    string(72) "<a href="http://www.novamov.com/video/mnzf1w7pp5lnf">Alice In Wonderland"

  }

}

 

I'm pretty new with arrays, but it looks like a double array and I just wanted to have the urls, no idea what to make with...

 

 

Link to comment
https://forums.phpfreaks.com/topic/203031-my-little-grabber/
Share on other sites

<?php
$url  = "http://www.novamov.com/search.php?q=Alice+in+wonderland&submit=";
$data = file_get_contents($url);
$searchterm = 'Alice in Wonderland';

preg_match_all('/<a href[^>]*>'.$searchterm.'/i', $data, $match);

$urls = array();

   foreach($match[0] as $link)
   {
      $link = explode('"', $link);
      $urls[] = $link[1];
   }

echo '<pre>' . print_r($urls, true) . '</pre>';

?>

Link to comment
https://forums.phpfreaks.com/topic/203031-my-little-grabber/#findComment-1063867
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.