I know this is probly has been covered many times, but what code can I use to grab a HTTP document and shove it into a variable?
Or is this not possible with PHP? then Javascript?
Is There No Way?
Printable View
I know this is probly has been covered many times, but what code can I use to grab a HTTP document and shove it into a variable?
Or is this not possible with PHP? then Javascript?
Is There No Way?
Try this:
When using fread, you might have to adjust the filesize parameter ($size).. it only reads 1.5MB in that example, but I'm betting that will be enough reading, although it might not be depending on whatever you are opening.. Anyway, that should get you started.Code:<?
$open = fopen("http://www.complex-sys.com/source/leetprogramming/index.php", "r"); //request file via HTTP
$size = 1500; //size in KB
$read = fread($open, $size * 1024); //store HTTP request in $read
fclose($open);
?>
I think i need CGI for what I'm doing...
When i have it say 'echo $open' it just says 'resource id #1' how might i be able to display it in this way?
echo $read;
yesssssssss!
TYSM!
-Resolved
:bigyello:
Isn't there some limitation by PHP on how big a string can be?
I'm now having problems with 'Large' strings...
Probably. No string can be larger than ~1.8 gigs on Windows, I think a little more in Linux. But PHP likely imposes more restrictions.
why is it cutting off half way through the web document? i'm guessing at the 1500KB mark...
Because the original code you have reads only 1500 KB.
Make a smaller buffer, read a block and write it out.
This should write out everything, no matter how large, in blocks of 4 KB.Code:<?
$open = fopen("http://www.complex-sys.com/source/leetprogramming/index.php", "r"); //request file via HTTP
while(($read = fread($open, 4096)) {
echo $read;
}
fclose($open);
?>
Sorry to annoy again butdoesnt work...least for me.Code:<?
$open = fopen("http://www.complex-sys.com/source/leetprogramming/index.php", "r"); //request file via HTTP
while($read = fread($open, 4096)) { //u could see it 2 ways, either you had an extra ) or one needed to be removed, *Fixed*
echo $read;
}
fclose($open);
?>
You might have to change something about the while loop. Read up on file I/O, you should find the solution.
u excluded a ')' :bigyello:
Don't blame me, it's 1AM here ;)
It's the codes fault, it should have know about your inaccuracy!:bigyello:
6:50PM Eastern
One more thing...
I wanted to use a variable for the site name, and this is what doesnt work
NM stupid me forgot a ';' and PHP had a spaz attack:bigyello:Code:$sitenam="http://www.thegh.org";
$open = fopen($sitenam, "r");
What error?
Another error...
why cant i do this?Code:$sitenam="www.google.com"; //any random site
$open = fopen($sitenam, "r");
//Open the site
while(($read = fread($open, 4096))) { //Open 4096bytes, or 4KB
echo ($read); //4KB onto the Client page, then go back for your brothers!
}
fclose($open);
Says:
Warning: fopen(www.google.com): failed to open stream: No such file or directory in v2.php on line 13
Warning: fread(): supplied argument is not a valid stream resource in v2.php on line 15
Warning: fclose(): supplied argument is not a valid stream resource in v2.php on line 18
$sitenam is going to be a form variable if i can get it working
The site name must start with http://
If you're grabbing the site name from a form and are worried about people entering in "http://" and don't want to prefix it yourself, try this:
It should work..PHP Code:<?
function checkURL($url){
if(!substr($url, 0, 7) == "http://"){
return "http://" . $url;
}
}
//used like so:
$sitenam = checkURL($_POST['site']);
?>
Too many functions, AHHHH... ok, i'll try to use it, TY.:bigyello:
Right now i'm having trouble using this ban list at:
http://tutorials.programmingsite.co.uk/banwords.php
i put the word 'ass' into the block list, and it blocks 'glass'
so i try using $addspace = (" ".$word); and i starts to ignore the function all together, i'm guessing, because it cant find the $word list.
if you want to do filter things at all you're going to be suffering quality.. if you block out just "ass", then it will filter things like glass, to make it "gl***", but if you just block out the word ass, like (" ass "), or something like that, whats going to stop someone from doing asss? you're gonna have to figure out what you want to filter out..
also, it would probably be easier to read if you posted the exact code you were using, and not just a link to a site with a copy of the code.. I'm guessing you changed something about it.
either live with it, or don't use a word filter..
The best way to do word filters is to use preg_replace() and regular expressions. That's the most efficient way.
Edit: Search these forums for examples. I've answered quite a few threads about it.