...

View Full Version : question on curl and preg_match_all



MattClark
09-16-2011, 09:46 PM
First off, this is the first time I've tried to us curl, so I'm kind of confused as to what is wrong in this script.

I'm using preg_match_all on a part of the page that is only there if the video is still available, but it always echo's out "TEST TEST THIS MOVIE SHOULD NEED TO BE FIXED"....Does this mean I'm doing my preg_match_all wrong? If it is able to find what I've set in preg_match_all, the code should do nothing, but it is always echoing out like the preg_match_all isn't there.



if($version1_source == 'sockshare.com') {
// check to see if video is still embedded on sockshare pages
$target_url = $version1;
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
curl_setopt($ch, CURLOPT_URL,$target_url);
curl_setopt($ch, CURLOPT_FAILONERROR, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_TIMEOUT, false);
$html = curl_exec($ch);
if (!$html) {
echo "<br />cURL error number:" .curl_errno($ch);
echo "<br />cURL error:" . curl_error($ch);
exit;
} else {

$version1_html = file_get_contents("$version1");
preg_match_all('/<div class="site-content">(.*)
<h1>(.*)
<strong>(.*)<\/strong>(.*)
<\/h1>(.*)
<div class="ad_728x90_top">/s', $version1_html, $version1_count, PREG_SET_ORDER);

if(isset($version1_count) && count($version1_count) == 1) {
// do nothing
} else {
echo $movie_id;
echo 'TEST TEST THIS MOVIE SHOULD NEED TO BE FIXED<br />';
}

}



}



Here is the html that I'm trying to preg_match_all to:



<div class="site-body">
<div class="site-content">
<h1>
I.Am.Number.Four.2011.PPVRip.IFLIX.avi
<strong>( 391.96 MB )</strong>
</h1>
<div class="ad_728x90_top">


However, the title/size obiviously varies depending on URL. Please help, if you have a moment!

Thanks!!

Inci
09-17-2011, 12:22 AM
Hello, yup, your preg_match is incorrect.


<?php

$string = '
<div class="site-body">
<div class="site-content">
<h1>
I.Am.Number.Four.2011.PPVRip.IFLIX.avi
<strong>( 391.96 MB )</strong>
</h1>
<div class="ad_728x90_top">
';

preg_match_all('/<div class="site-body">\s*?<div class="site-content">\s*?<h1>\s*?(.*?)<strong>\(\s*?(.*?)\s*?\)<\/strong>\s*?<\/h1>/s', $string, $version1_count, PREG_SET_ORDER);

print_r($version1_count);
?>


you will get name of video in $version1_count[1] and its size in $version1_count[2]. just check any of em or both for their set and that will mean that video here.

like this

if ((isset($version1_count[1]) && ($version1_count[1]))) { it's matched } else { not matched }

Btw - preg_match_all returns array not variable.

MattClark
09-17-2011, 12:45 AM
Ahh, well I'm trying to make it check around 25,000 pages at once, and the page titles vary, and I have no way to check it by that. I was hoping to check it by the html there. Can I check it against whether or not that string of html is there?

Inci
09-17-2011, 01:01 AM
hello again, i already gave you the string ;))



preg_match_all('/<div class="site-body">\s*?<div class="site-content">\s*?<h1>\s*?(.*?)<strong>\(\s*?(.*?)\s*?\)<\/strong>\s*?<\/h1>/s', $version1_html, $version1_count, PREG_SET_ORDER);


also you need to change this block



if(isset($version1_count) && count($version1_count) == 1) {
// do nothing
} else {
echo $movie_id;
echo 'TEST TEST THIS MOVIE SHOULD NEED TO BE FIXED<br />';
}


to



if ((isset($version1_count[1]) && ($version1_count[1]))) {
// do nothing
} else {
echo $movie_id;
echo 'TEST TEST THIS MOVIE SHOULD NEED TO BE FIXED<br />';
}


hope it will help you.

MattClark
09-17-2011, 10:09 AM
Alright, starting to get it all figured out now. Thanks so much!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum