Need help Making Script Work

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ojsimon
    New Member
    • May 2007
    • 59

    Need help Making Script Work

    Hi
    I found this script on a forum and have been trying to make it work, but all it returns is a blank screen, i tried using the debug error reporting but got nothing from that either just a blank page, here is the code[PHP]<?php
    //In this case, it fetches a search for "fresh content" from www.alltheweb.c om, whom we hope you will visit.
    $theLocation="h ttp://www.alltheweb.c om/search?cat=web& q=fresh+content &phrase=on&h=50 ";
    //Below, at $start and $finish, you'll enter the start and finish points in the remote HTML.

    $startingpoint = "<td valign=top>&nbs p;1.&nbsp;&nbsp ;</td>"; // replace inside the quotes with with your unique start point in the source of the HTML page. It HAS to be unique.
    $endingpoint = "<span class=rh>Result s:</span></b>&nbsp;&nbsp;" ; // replace with the unique finish point in the source of the HTML page
    //Don't forget to escape any " marks with a \ mark.
    // Example: If the starting HTML is: <img src="images/something.jpg">
    // You would tell Mini-Fetch: $startingpoint = "<img src=\"images/something.jpg\" >";

    //That's probably all you need to edit, unless you want to match and replace certain text or HTML.

    // - "Don't touch this part..."
    preg_match("/^(https?:\/\/)?([^\/]*)(.*)/i", "$theLocati on", $matches);
    $theDomain = "http://" . $matches[2];
    $page = $matches[3];

    $fd = fopen($theDomai n.$page, "r"); // can change to "rb", on NT/2000 servers, if problems.
    $value = "";
    while(!feof($fd )){
    $value .= fread($fd, 4096);
    }
    fclose($fd);
    $start= strpos($value, "$startingpoint ");
    $finish= strpos($value, "$endingpoint") ;
    $length= $finish-$start;
    $value=substr($ value, $start, $length);
    // end "don't touch this part"


    // eregi_replace, below, is a case-insensitive function to find, match, and replace variations of text that you define.
    //The following commands strip or replace HTML tags.
    //To NOT strip a certain HTML tag, add // before the line in question.
    // the "", before the $value at the end of the line means replace the tag with blank space, which effectively deletes the tag.

    // $value = eregi_replace( "<img src=[^>]*>", "", $value ); // Remove all image tags. This is disabled until you remove the // in front of this line.
    $value = eregi_replace( "<IMG alt=[^>]*>", "", $value ); // Remove all image alt="whatever" tags
    $value = eregi_replace( "<class[^>]*>", "", $value ); // Remove all variations of <class> tags.
    $value = eregi_replace( "<table[^>]*>", "", $value ); // Remove ALL variations of <table> tags.
    $value = eregi_replace( "<tr[^>]*>", "", $value ); // Replace <tr> tags with blank space.
    $value = eregi_replace( "<td[^>]*>", "", $value ); // Remove all variations of <td> tags.

    // Below - what's the difference, you ask, between eregi_replace and str_replace?
    // str_replace is faster, by a long shot... The catch is that in can only be used
    // to replace EXACT value matches, as you see below, and doesn't work well in huge files without using arrays.
    $value = str_replace( "</font>", "", $value ); // Remove closing </font> tags.
    $value = str_replace( "</table>", "", $value ); // Remove closing </table> tags.
    $value = str_replace( "</tr>", "", $value ); // Remove closing </tr> tags.
    $value = str_replace( "</td>", "", $value ); // Remove closing </td> tags.
    $value = str_replace( "<center>", "", $value ); // Remove <center> tag...
    $value = str_replace( "</center>", "", $value ); // ...alignment calls.
    $value = str_replace( "<b>", "", $value ); // Remove <b> tags.
    $value = str_replace( "</b>", "", $value ); // Remove closing </b> tags...

    // More tags. Just take out the // in front and edit as you like.
    //$value = eregi_replace( "Competitor s name", "", $value ); // Remove certain text...
    //$value = eregi_replace( "<javascrip t[^>]*>", "", $value ); //remove javascripts
    //$value = eregi_replace( "<script[^>]*>", "", $value ); //remove scripts

    // replace normal links with HTML to open fetched links in new window
    $value = eregi_replace( "href=", "target=\"_blan k\" href=", $value );

    // open links that use " in new window
    $value = eregi_replace( "href=\"", "target=\"_blan k\" href=\"", $value );

    $FinalOutput = preg_replace("/(href=\"?)(\/[^\"\/]+)/", "\\1" . $theDomain . "\\2", $value);
    echo $FinalOutput; //prints it to your page
    flush (); //force output to your page faster

    ?>[/PHP]
  • nomad
    Recognized Expert Contributor
    • Mar 2007
    • 664

    #2
    tell me what are you trying to do here?

    nomad

    Comment

    • ojsimon
      New Member
      • May 2007
      • 59

      #3
      Hi
      I'm trying to use this to get information from a certain site, although it is set to alltheweb at the moment, i would like to use it to grab the price of kelkoo.co.uk

      Thanks

      Comment

      • nomad
        Recognized Expert Contributor
        • Mar 2007
        • 664

        #4
        Originally posted by ojsimon
        Hi
        I'm trying to use this to get information from a certain site, although it is set to alltheweb at the moment, i would like to use it to grab the price of kelkoo.co.uk

        Thanks
        This is your problem here:
        [PHP]$value =substr($value, $start, $length);[/PHP]

        Your String $value is not right Take a look at your while statement. Notice the string $value . in that statement.

        nomad

        Comment

        • ojsimon
          New Member
          • May 2007
          • 59

          #5
          Hi thanks for your help but what is wrong with the $value variable? i am new to php and am unure, secondly how do i fix this problem?

          Thanks
          Olie

          Comment

          • nomad
            Recognized Expert Contributor
            • Mar 2007
            • 664

            #6
            Originally posted by ojsimon
            Hi thanks for your help but what is wrong with the $value variable? i am new to php and am unure, secondly how do i fix this problem?

            Thanks
            Olie
            ok you need to
            $value . =

            try that and it should work.

            Comment

            • ojsimon
              New Member
              • May 2007
              • 59

              #7
              Hi
              Thanks for your help but it is still not working, i also tried changing the site that it was getting the info from i am now running
              Code:
              <?php
              
              
              //In this case, it fetches a search for "fresh content" from www.alltheweb.com, whom we hope you will visit.
              $theLocation="http://en.wikipedia.org/wiki/Nokia";
              //Below, at $start and $finish, you'll enter the start and finish points in the remote HTML.
              
              $startingpoint = "<link rel="search" type="application/opensearchdescription+xml" href="/w/opensearch_desc.php" title="Wikipedia (English)" />"; // replace inside the quotes with with your unique start point in the source of the HTML page. It HAS to be unique.
              $endingpoint = "<li class="interwiki-hu">"; // replace with the unique finish point in the source of the HTML page 
              //Don't forget to escape any " marks with a \ mark.
              // Example: If the starting HTML is:  <img src="images/something.jpg">
              // You would tell Mini-Fetch: $startingpoint = "<img src=\"images/something.jpg\">";
              
              //That's probably all you need to edit, unless you want to match and replace certain text or HTML.
              
              // - "Don't touch this part..."
              preg_match("/^(https?:\/\/)?([^\/]*)(.*)/i", "$theLocation", $matches);
              $theDomain = "http://" . $matches[2];
              $page = $matches[3];
              
              $fd = fopen($theDomain.$page, "r"); // can change to "rb",  on NT/2000 servers, if problems.
              $value = "";
              while(!feof($fd)){
              	$value .= fread($fd, 4096);	
              }
              fclose($fd);
              $start= strpos($value, "$startingpoint");  
              $finish= strpos($value, "$endingpoint");  
              $length= $finish-$start;
              $value.=substr($value, $start, $length);
              // end "don't touch this part"
              
              
              // eregi_replace, below, is a case-insensitive function to find, match, and replace variations of text that you define.
              //The following commands strip or replace HTML tags. 
              //To NOT strip a certain HTML tag, add // before the line in question.
              // the "", before the $value at the end of the line means replace the tag with blank space, which effectively deletes the tag.
              
              // $value = eregi_replace( "<img src=[^>]*>", "", $value );   // Remove all image tags. This is disabled until you remove the // in front of this line.
              $value = eregi_replace( "<IMG alt=[^>]*>", "", $value );   // Remove all image alt="whatever" tags
              $value = eregi_replace( "<class[^>]*>", "", $value ); // Remove all variations of <class> tags.
              $value = eregi_replace( "<table[^>]*>", "", $value ); // Remove ALL variations of <table> tags.
              $value = eregi_replace( "<tr[^>]*>", "", $value ); // Replace <tr> tags with  blank space.
              $value = eregi_replace( "<td[^>]*>", "", $value ); // Remove all variations of <td> tags.
              
              // Below - what's the difference, you ask, between eregi_replace and str_replace?
              // str_replace is faster, by a long shot... The catch is that in can only be used
              // to replace EXACT value matches, as you see below, and doesn't work well in huge files without using arrays.
              $value = str_replace( "</font>", "", $value ); // Remove closing </font> tags.
              $value = str_replace( "</table>", "", $value ); // Remove closing </table> tags.
              $value = str_replace( "</tr>", "", $value );  // Remove closing </tr> tags.
              $value = str_replace( "</td>", "", $value ); // Remove closing </td> tags.
              $value = str_replace( "<center>", "", $value ); // Remove <center> tag...
              $value = str_replace( "</center>", "", $value ); // ...alignment calls.
              $value = str_replace( "<b>", "", $value ); // Remove <b> tags.
              $value = str_replace( "</b>", "", $value ); // Remove closing </b> tags...
              
              // More tags. Just take out the // in front and edit as you like.
              //$value = eregi_replace( "Competitors name", "", $value ); // Remove certain text...
              //$value = eregi_replace( "<javascript[^>]*>", "", $value ); //remove javascripts
              //$value = eregi_replace( "<script[^>]*>", "", $value ); //remove scripts
              
              // replace normal links with HTML to open fetched links in new window
              $value = eregi_replace( "href=", "target=\"_blank\" href=", $value ); 
              
              // open links that use " in new window 
              $value = eregi_replace( "href=\"", "target=\"_blank\" href=\"", $value ); 
              
              $FinalOutput = preg_replace("/(href=\"?)(\/[^\"\/]+)/", "\\1" . $theDomain . "\\2", $value);
              echo $FinalOutput; //prints it to your page
              ?>

              Comment

              • ojsimon
                New Member
                • May 2007
                • 59

                #8
                Please can someone help me.

                Thanks

                Comment

                Working...