473,385 Members | 1,838 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Need help Making Script Work

59
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.com, whom we hope you will visit.
$theLocation="http://www.alltheweb.com/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>&nbsp;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>Results:</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", "$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
flush (); //force output to your page faster

?>[/PHP]
Feb 13 '08 #1
7 2880
nomad
664 Expert 512MB
tell me what are you trying to do here?

nomad
Feb 13 '08 #2
ojsimon
59
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
Feb 14 '08 #3
nomad
664 Expert 512MB
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
Feb 14 '08 #4
ojsimon
59
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
Feb 14 '08 #5
nomad
664 Expert 512MB
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.
Feb 14 '08 #6
ojsimon
59
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
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3.  
  4. //In this case, it fetches a search for "fresh content" from www.alltheweb.com, whom we hope you will visit.
  5. $theLocation="http://en.wikipedia.org/wiki/Nokia";
  6. //Below, at $start and $finish, you'll enter the start and finish points in the remote HTML.
  7.  
  8. $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.
  9. $endingpoint = "<li class="interwiki-hu">"; // replace with the unique finish point in the source of the HTML page 
  10. //Don't forget to escape any " marks with a \ mark.
  11. // Example: If the starting HTML is:  <img src="images/something.jpg">
  12. // You would tell Mini-Fetch: $startingpoint = "<img src=\"images/something.jpg\">";
  13.  
  14. //That's probably all you need to edit, unless you want to match and replace certain text or HTML.
  15.  
  16. // - "Don't touch this part..."
  17. preg_match("/^(https?:\/\/)?([^\/]*)(.*)/i", "$theLocation", $matches);
  18. $theDomain = "http://" . $matches[2];
  19. $page = $matches[3];
  20.  
  21. $fd = fopen($theDomain.$page, "r"); // can change to "rb",  on NT/2000 servers, if problems.
  22. $value = "";
  23. while(!feof($fd)){
  24.     $value .= fread($fd, 4096);    
  25. }
  26. fclose($fd);
  27. $start= strpos($value, "$startingpoint");  
  28. $finish= strpos($value, "$endingpoint");  
  29. $length= $finish-$start;
  30. $value.=substr($value, $start, $length);
  31. // end "don't touch this part"
  32.  
  33.  
  34. // eregi_replace, below, is a case-insensitive function to find, match, and replace variations of text that you define.
  35. //The following commands strip or replace HTML tags. 
  36. //To NOT strip a certain HTML tag, add // before the line in question.
  37. // the "", before the $value at the end of the line means replace the tag with blank space, which effectively deletes the tag.
  38.  
  39. // $value = eregi_replace( "<img src=[^>]*>", "", $value );   // Remove all image tags. This is disabled until you remove the // in front of this line.
  40. $value = eregi_replace( "<IMG alt=[^>]*>", "", $value );   // Remove all image alt="whatever" tags
  41. $value = eregi_replace( "<class[^>]*>", "", $value ); // Remove all variations of <class> tags.
  42. $value = eregi_replace( "<table[^>]*>", "", $value ); // Remove ALL variations of <table> tags.
  43. $value = eregi_replace( "<tr[^>]*>", "", $value ); // Replace <tr> tags with  blank space.
  44. $value = eregi_replace( "<td[^>]*>", "", $value ); // Remove all variations of <td> tags.
  45.  
  46. // Below - what's the difference, you ask, between eregi_replace and str_replace?
  47. // str_replace is faster, by a long shot... The catch is that in can only be used
  48. // to replace EXACT value matches, as you see below, and doesn't work well in huge files without using arrays.
  49. $value = str_replace( "</font>", "", $value ); // Remove closing </font> tags.
  50. $value = str_replace( "</table>", "", $value ); // Remove closing </table> tags.
  51. $value = str_replace( "</tr>", "", $value );  // Remove closing </tr> tags.
  52. $value = str_replace( "</td>", "", $value ); // Remove closing </td> tags.
  53. $value = str_replace( "<center>", "", $value ); // Remove <center> tag...
  54. $value = str_replace( "</center>", "", $value ); // ...alignment calls.
  55. $value = str_replace( "<b>", "", $value ); // Remove <b> tags.
  56. $value = str_replace( "</b>", "", $value ); // Remove closing </b> tags...
  57.  
  58. // More tags. Just take out the // in front and edit as you like.
  59. //$value = eregi_replace( "Competitors name", "", $value ); // Remove certain text...
  60. //$value = eregi_replace( "<javascript[^>]*>", "", $value ); //remove javascripts
  61. //$value = eregi_replace( "<script[^>]*>", "", $value ); //remove scripts
  62.  
  63. // replace normal links with HTML to open fetched links in new window
  64. $value = eregi_replace( "href=", "target=\"_blank\" href=", $value ); 
  65.  
  66. // open links that use " in new window 
  67. $value = eregi_replace( "href=\"", "target=\"_blank\" href=\"", $value ); 
  68.  
  69. $FinalOutput = preg_replace("/(href=\"?)(\/[^\"\/]+)/", "\\1" . $theDomain . "\\2", $value);
  70. echo $FinalOutput; //prints it to your page
  71. ?>
Feb 14 '08 #7
ojsimon
59
Please can someone help me.

Thanks
Feb 16 '08 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: |-|erc | last post by:
Hi! Small challenge for you. The index.php uses this file and calls layout(). Take a look at www.chatty.net this file draws the chat login box on the right. I traced the CHAT button it submits...
8
by: George Hester | last post by:
In a page I have when the user left-clicks the page a Input box for a form gets the focus. But if the user right-clicks the page the Input box is not getting the focus. I'd like the Input box to...
4
by: Bob | last post by:
Below is sample code that illustrates what I'm trying to do. For sake of brevity I didn't include the properties of buildBtn that determine what data to request. The problem is I never see...
0
by: EasyRider41 | last post by:
I am trying to merge to scripting samples I for on a source code web site and having limited luck. Then first one is called Zebra Tables witch colors alternate rows of a table to look beter. The...
2
by: Stewart | last post by:
Originally posted in comp.lang.javascript: Newsgroups: comp.lang.javascript From: "Stewart" Date: 23 Aug 2005 02:50:04 -0700 Local: Tues, Aug 23 2005 10:50 am Subject: FireFox, RemoveChild,...
18
by: Q. John Chen | last post by:
I have Vidation Controls First One: Simple exluce certain special characters: say no a or b or c in the string: * Second One: I required date be entered in "MM/DD/YYYY" format: //+4 How...
9
by: Mickey Segal | last post by:
The long-simmering Eolas patent dispute: http://www.microsoft.com/presspass/press/2003/oct03/10-06EOLASPR.mspx has led to an optional Microsoft Update: http://support.microsoft.com/kb/912945/en-us...
2
by: ranger7419 | last post by:
I'm trying to figure out why this script will work in IE 6 but not Firefox, and so I need someone here with a far better grasp on javascript to explain this. Basically, I have a page with several...
20
by: mike | last post by:
I help manage a large web site, one that has over 600 html pages... It's a reference site for ham radio folks and as an example, one page indexes over 1.8 gb of on-line PDF documents. The site...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.