Jump to content

Regex and Preg_Match


falarious

Recommended Posts

Hello guys! This is part of a script that grabs the latest videos and thumbnails of a popular video website. It worked well until they changed layouts. I fixed some stuff up, but my coding skills are limited. If one of you guys could look over it for errors that would be great! I bolded the parts that have possible errors.

 

function fetch_new()

{

global $page_no, $fetched, $new;

 

$page = @file_get_contents("http://www.stupidvideos.com/videos/all/new/$page_no");

preg_match_all("#<div class=\"video_box\"><a href=\"/video/all/([^/]*)/\" title=\".*\"><img src=\"http://images.stupidvideos.com/images/([^\"]*)\" width=\"120\" height=\"90\" alt=\"\"></a></div>#", $page, $matches);

 

$new2 = get_new_elements($matches[1], $fetched);

$new = array_merge($new, $new2);

$new = array_unique($new);

}

 

/*

done fncs

*/

 

 

 

$no = 0 + $_GET['no'];

 

if(empty($no))

{

$no = 5;

}

elseif($no > 20)

{

$no = 20;

}

 

$page = @file_get_contents("http://www.stupidvideos.com/videos/all/new/1");

 

preg_match_all("#<div class=\"video_box\"><a href=\"/video/all/([^/]*)/\" title=\".*\"><img src=\"http://images.stupidvideos.com/images/([^\"]*)\" width=\"120\" height=\"90\" alt=\"\"></a></div>#", $page, $matches);

 

$file = @file_get_contents('files/videos/videos/fetchlog');

$fetched = explode("\r\n", trim($file));

 

$new = get_new_elements($matches[1], $fetched);

 

$page_no = floor((count($fetched)/20));

while(count($new) < $no)

{

fetch_new();

$page_no++;

}

 

$new = array_values($new);

 

require_once('config.php');

if(@mysql_connect(DBHOST, DBUSER, DBPASS))

{

@mysql_select_db(DB);

}

 

 

for($i=0; ($i<$no && $i<count($new)); $i++)

{

@file_put_contents('files/videos/videos/fetchlog', $new[$i] . "\r\n", FILE_APPEND);

 

$page = @file_get_contents("http://www.stupidvideos.com/video/all/$new[$i]/?m=new");

 

if(!preg_match("/<META name=\"description\" content=\"([^\"]*)\"><meta name=\"title\" content=\"([^\"]*)\"\/>.*<link rel=\"videothumbnail\" href=\"([^\"]*)\" type=\"image\/jpeg\"\/>/", $page, $matches))

{

continue;

}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.