Results 1 to 16 of 16

Thread: [RESOLVED] Anything wrong with this code?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2007
    Posts
    190

    Resolved [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.

  2. #2
    PowerPoster lintz's Avatar
    Join Date
    Mar 2003
    Location
    The 19th Hole
    Posts
    2,697

    Re: Anything wrong with this code?

    Replace Split with Explode.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jan 2007
    Posts
    190

    Re: Anything wrong with this code?

    Just tried and it didn't do anything.

  4. #4
    Hyperactive Member
    Join Date
    Dec 2006
    Location
    Ubuntu Haters Club
    Posts
    405

    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.

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Jan 2007
    Posts
    190

    Re: Anything wrong with this code?

    Notice: Undefined offset: 1 in file.php on line 21

    Thats what I get.

  6. #6
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Re: Anything wrong with this code?

    what line is line 21?
    My usual boring signature: Something

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Jan 2007
    Posts
    190

    Re: Anything wrong with this code?

    Code:
    $explode2 = explode(" </b>." , $explode[1]);

  8. #8
    Hyperactive Member
    Join Date
    Dec 2006
    Location
    Ubuntu Haters Club
    Posts
    405

    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.

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Jan 2007
    Posts
    190

    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

  10. #10
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    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.

  11. #11

    Thread Starter
    Addicted Member
    Join Date
    Jan 2007
    Posts
    190

    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.

  12. #12
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    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.

  13. #13

    Thread Starter
    Addicted Member
    Join Date
    Jan 2007
    Posts
    190

    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.

  14. #14
    Hyperactive Member
    Join Date
    Dec 2006
    Location
    Ubuntu Haters Club
    Posts
    405

    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.

  15. #15
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    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); 

  16. #16

    Thread Starter
    Addicted Member
    Join Date
    Jan 2007
    Posts
    190

    Re: Anything wrong with this code?

    Thanks did it:-

    PHP Code:
       $ch curl_init();
       
    curl_setopt($chCURLOPT_URL"https://ssl.rapidshare.com/cgi-bin/premiumzone.cgi"); 
       
    curl_setopt($chCURLOPT_FOLLOWLOCATION1);
       
    curl_setopt($chCURLOPT_RETURNTRANSFER1);
       
    curl_setopt($chCURLOPT_SSL_VERIFYPEER0);
       
    curl_setopt($chCURLOPT_POST1);
       
    curl_setopt($chCURLOPT_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
  •  



Click Here to Expand Forum to Full Width