|
-
Jul 31st, 2007, 08:35 PM
#1
Thread Starter
Addicted Member
[RESOLVED] Anything wrong with this code?
PHP Code:
function Bandwidth() {
$page = @file_get_contents('https://ssl.rapidshare.com/cgi-bin/premiumzone.cgi?login=USERNAME&password=PASSWORD');
$splitx = split("5 days you have downloaded <b>", $page);
$splitx2 = split(" </b>." , $splitx[1]);
$result = $splitx2[0];
if ( $result == "" ) {
return "Unknown Error!";
}else{
return $result;
}
}
Bandwidth()
Is there anything wrong with that code? When I run the code it returns nothing.
-
Aug 1st, 2007, 12:12 AM
#2
Re: Anything wrong with this code?
Replace Split with Explode.
-
Aug 1st, 2007, 06:49 AM
#3
Thread Starter
Addicted Member
Re: Anything wrong with this code?
Just tried and it didn't do anything.
-
Aug 2nd, 2007, 05:33 AM
#4
Hyperactive Member
Re: Anything wrong with this code?
PHP Code:
error_reporting(E_ALL);
// But wait, it's not meant to do anything!!
echo Bandwidth(); // <-- More what you want...
» Twitter: @rudi_visser : Website: www.rudiv.se «
If Apple fixes security flaws, they are heralded as proactive. If Microsoft fixes a security flaw, they finally got around to fixing their buggy OS.
-
Aug 2nd, 2007, 01:20 PM
#5
Thread Starter
Addicted Member
Re: Anything wrong with this code?
Notice: Undefined offset: 1 in file.php on line 21
Thats what I get.
-
Aug 2nd, 2007, 01:40 PM
#6
Re: Anything wrong with this code?
My usual boring signature: Something
-
Aug 2nd, 2007, 01:57 PM
#7
Thread Starter
Addicted Member
Re: Anything wrong with this code?
Code:
$explode2 = explode(" </b>." , $explode[1]);
-
Aug 2nd, 2007, 03:37 PM
#8
Hyperactive Member
Re: Anything wrong with this code?
Thanks for putting it in context, I guess your code is as follows, am I correct?
PHP Code:
$explode1 = explode("5 days you have downloaded <b>", $page);
$explode2 = explode(" </b>." , $explode[1]);
$result = $explode2[0];
If so then do some error handling after $explode1, namely:
PHP Code:
if(isset($explode1[1]) {
$explode2 = explode(" </b>.", $explode[1]);
} else {
return false
}
» Twitter: @rudi_visser : Website: www.rudiv.se «
If Apple fixes security flaws, they are heralded as proactive. If Microsoft fixes a security flaw, they finally got around to fixing their buggy OS.
-
Aug 2nd, 2007, 04:52 PM
#9
Thread Starter
Addicted Member
Re: Anything wrong with this code?
PHP Code:
<?php
function Bandwidth() {
$page = @file_get_contents('https://ssl.rapidshare.com/cgi-bin/premiumzone.cgi?login=USER&password=PASS');
$explode1 = explode("5 days you have downloaded <b>", $page);
if(isset($explode1)) {
$explode2 = explode(" </b>.", $explode1);
} else {
return false;
}
$result = $explode2;
if ( $result == "" ) {
return "Unknown Error!";
}else{
return $result;
}
}
error_reporting(E_ALL);
echo Bandwidth();
?>
When I run it..
Notice: Array to string conversion in ra.php on line 8
Array
-
Aug 2nd, 2007, 11:16 PM
#10
Re: Anything wrong with this code?
Why are you using explode()? Use preg_match if you want to find a particular section of text on the page.
-
Aug 3rd, 2007, 11:48 PM
#11
Thread Starter
Addicted Member
Re: Anything wrong with this code?
How would I use preg match to get the numbers in between the sentence? Thought it only could see if a word is in a string.
-
Aug 4th, 2007, 01:01 AM
#12
Re: Anything wrong with this code?
Regular expressions are useful for finding any pattern in text whether textual, numeric, or otherwise.
Give us an example of the complete string and the output you want from it, and we can try and come up with a regular expression to match the part you want.
You should also look at http://regular-expressions.info/ which is a good resource for learning how to write regular expressions.
-
Aug 4th, 2007, 01:35 AM
#13
Thread Starter
Addicted Member
Re: Anything wrong with this code?
last 5 days you have downloaded <b>random number</b>.
In between the bold tags is a random number.
I want it to output the random number.
-
Aug 4th, 2007, 07:56 AM
#14
Hyperactive Member
Re: Anything wrong with this code?
PHP Code:
preg_match('/last 5 days you have downloaded \<b\>([0-9]*?)\<\/b\>./', $page, $matches);
$matches[1]; // This should be the number [UNTESTED]
» Twitter: @rudi_visser : Website: www.rudiv.se «
If Apple fixes security flaws, they are heralded as proactive. If Microsoft fixes a security flaw, they finally got around to fixing their buggy OS.
-
Aug 4th, 2007, 08:37 AM
#15
Re: Anything wrong with this code?
You don't actually need to escape all of those characters:
PHP Code:
preg_match('#last 5 days you have downloaded <b>(\d+)</b>.#si', $text, $matches);
-
Aug 4th, 2007, 11:48 AM
#16
Thread Starter
Addicted Member
Re: Anything wrong with this code?
Thanks did it:-
PHP Code:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://ssl.rapidshare.com/cgi-bin/premiumzone.cgi");
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "login=&password=");
$pagedata = curl_exec($ch);
curl_close($ch);
ereg("Used disk-space: <b>([0-9\.]+) MB</b>", $pagedata, $matches);
echo "Uploaded: $matches[1] MB";
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|