read from remote url and save it to mysql

Discussion in 'PHP' started by tastro, Feb 11, 2009.

  1. #1
    tastro, Feb 11, 2009 IP
  2. Danltn

    Danltn Well-Known Member

    Messages:
    679
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    120
    #2
    function getRapidshareLinks($url = '')
    {
    	if(!$url) throw new Exception('No URL provided.');
    	preg_match_all('/rapidshare.com\/files\/[0-9]{1,9}\/[a-z0-9-_\.]+/i', $page = file_get_contents($url), $matches);
    	return array_map(create_function('$url', 'return \'http://\' . $url;'), $matches[0]);
    }
    PHP:
    You can save it to an SQL yourself, easy enough - but I can understand how Regex can be confusing at first.

    Example:
    print_r(getRapidshareLinks('http://www.haktec.com/3677-download-Meet-the-Browns-2008.html'));
    PHP:
     
    Danltn, Feb 12, 2009 IP
  3. tastro

    tastro Member

    Messages:
    68
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #3
    i done it myself before but the problem was to configure preg_match_all correct :D thank you very much dude :p
     
    tastro, Feb 12, 2009 IP
  4. tastro

    tastro Member

    Messages:
    68
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #4
    hi,

    but now when i try to insert it into mysql it does insert 'array' and not the links :S
    i did it like this:

    $test = getRapidshareLinks('http://www.haktec.com/3677-download-Meet-the-Browns-2008.html');
    print $test;

    and inserted $test into mysql :S

    how to make this work ? :S

    thank you, tastro
     
    tastro, Feb 12, 2009 IP
  5. tastro

    tastro Member

    Messages:
    68
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #5
    ah... i think that i'm getting it :D i just have to include a loop actiob (FOR or WHILE) and then insert it like $test[$i] right ? $i is the loop, but anyways... an example would be nice :p thank you again :>
     
    tastro, Feb 12, 2009 IP
  6. tastro

    tastro Member

    Messages:
    68
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #6
    ok, now i have it like this:

    function getRapidshareLinks($url = '')
    {
    if(!$url) throw new Exception('No URL provided.');
    preg_match_all('/rapidshare.com\/files\/[0-9]{1,9}\/[a-z0-9-_\.]+/i', $page = file_get_contents($url), $matches);
    return array_map(create_function('$url', 'return \'http://\' . $url;'), $matches[0]);
    }
    $test = getRapidshareLinks('http://www.haktec.com/3677-download-Meet-the-Browns-2008.html');
    for ($i=0; $i<count($test); $i++) {
    $lol = "".$test[$i]."\n";
    }

    but now it does add every rapidshare link to it's own field in mysql, and i want to add all the rapidshare links from one url to the same field.

    mysql_query("INSERT INTO rslinks (test) "."VALUES ('$lol')");
     
    tastro, Feb 12, 2009 IP
  7. tastro

    tastro Member

    Messages:
    68
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #7
    thank you very much to all that pmed me and or replayed here. no more help needed ;) all is working fine :p
     
    tastro, Feb 13, 2009 IP
  8. Danltn

    Danltn Well-Known Member

    Messages:
    679
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    120
    #8
    $links = implode(',', getRapidshareLinks($url));
     
    Danltn, Feb 18, 2009 IP