Randy Johnson
asked on
Script that pulls a webpage
can anybody give me some code that will
grab a webpage from inside the script ie http://www.domain.com
and then go through the page line by line looking for something?
Thanks,
Randu
grab a webpage from inside the script ie http://www.domain.com
and then go through the page line by line looking for something?
Thanks,
Randu
file_get_contents() -- Reads entire file into a string just like file()
ASKER
Why does this str replaces not work? I am using this for testing purposed to learn how to do this. I maybe going at it all wrong
<?php
// Get a file into an array. In this example we'll go through HTTP to get
// the HTML source of a URL.
$lines = file('http://www.chaoticage.com/scores_1.php');
// Loop through our array, show HTML source as HTML source; and line numbers too.
foreach ($lines as $line_num => $line) {
if(strstr($line,'<tr><td>' )) {
#str_replace("this","that" ,$line);
substr_replace('<tr><td>', "",$line);
#str_replace("","",$line);
substr_replace("</td><td>" ,";",$line );
substr_replace("</td><td style=\"text-align: left;\">",";",$line);
substr_replace("</td><td style=\"color:#FF0000;\">" ,";",$line );
echo($line);
#exit;
#echo "Line #<b>{$line_num}</b> : " . htmlspecialchars($line) . "<br />\n";
}
}
?>
<?php
// Get a file into an array. In this example we'll go through HTTP to get
// the HTML source of a URL.
$lines = file('http://www.chaoticage.com/scores_1.php');
// Loop through our array, show HTML source as HTML source; and line numbers too.
foreach ($lines as $line_num => $line) {
if(strstr($line,'<tr><td>'
#str_replace("this","that"
substr_replace('<tr><td>',
#str_replace("","",$line);
substr_replace("</td><td>"
substr_replace("</td><td style=\"text-align: left;\">",";",$line);
substr_replace("</td><td style=\"color:#FF0000;\">"
echo($line);
#exit;
#echo "Line #<b>{$line_num}</b> : " . htmlspecialchars($line) . "<br />\n";
}
}
?>
ASKER
I have also tried str_replace and that does not work either :-( any ideas?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
oh gosh, that was a bone head mistake... I will let you know how it goes
Randy
Randy
There are some examples here:
http://us4.php.net/function.file
<?php
// Get a file into an array. In this example we'll go through HTTP to get
// the HTML source of a URL.
$lines = file('http://www.example.com/');
// Loop through our array, show HTML source as HTML source; and line numbers too.
foreach ($lines as $line_num => $line) {
echo "Line #<b>{$line_num}</b> : " . htmlspecialchars($line) . "<br />\n";
}
// Another example, let's get a web page into a string. See also file_get_contents().
$html = implode('', file('http://www.example.com/'));
?>
venkat