Forum Moderators: coopster
I am used to using the Perl LWP module to fetch data from remote webpages. However, i need to know how this can be done in PHP. Can someone please tell me how i can fetch the entire content of a remote page using php and put the following at the begining of each new line:
document.write("
and put the following at the end of each line:
")
any help would be appreciated.
cheers
include ("http[b]:[/b]//www.example.com/page.htm"); or curl, if you want to alter / parse the response:
$url = "http[b]:[/b]//www.example.com/page.htm";
$curl = curl_init ();
curl_setopt ($curl, CURLOPT_URL, $url);
curl_setopt ($curl, CURLOPT_HEADER, 0);
curl_setopt ($curl, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec ($curl);
curl_close($curl);
print $result;
$open = fopen("http://www.example.com/page.htm", "r");
$read = fread($open, 9024);
fclose($open);
echo $read;
But i need to add something at the begining of each line and at the end of each line. I was thinking of using the str_replace function but cant seem to find a way of using it to do it.
any advice would be appreciated.
cheers
Yah, sorry that i didn't mention it. You'd need to install the Curl Library [curl.haxx.se].
>fopen
>need to add something at the begining of each line and at the end of each line.
You could use the str_replace or ereg_replace function to search and replace the returns \n.
$read = ereg_replace ("\n", "\ndocument.write('", $read);
$read = ereg_replace ("\n", "')\n", $read);
Isnt there any other functions to allow adding something to the end of each line?
gethan, your code seems to do the trick. However, there is one problem. For some reason the code puts the ') on on a new line. so for example if I have a <tr> tag it will put it like this:
document.write('<tr>
')
i need the ') to move to the same line so it will end up looking like this
document.write('<tr>')
any ideas?
Cheers
[hu.php.net...]
Strips out the whitespace, newlines, tabs etc from each line.
HTH