|
-
Jan 8th, 2004, 08:52 PM
#1
Thread Starter
New Member
Grab Source, AGAIN!
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?
Last edited by x198; Jan 10th, 2004 at 01:55 PM.
-
Jan 9th, 2004, 01:01 AM
#2
Try this:
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);
?>
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.
-
Jan 9th, 2004, 06:16 AM
#3
Thread Starter
New Member
ah
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?
-
Jan 9th, 2004, 06:49 AM
#4
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Jan 9th, 2004, 03:41 PM
#5
Thread Starter
New Member
yesssssssss!
TYSM!
-Resolved
-
Jan 10th, 2004, 01:56 PM
#6
Thread Starter
New Member
Isn't there some limitation by PHP on how big a string can be?
I'm now having problems with 'Large' strings...
-
Jan 10th, 2004, 02:01 PM
#7
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.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Jan 10th, 2004, 02:03 PM
#8
Thread Starter
New Member
why is it cutting off half way through the web document? i'm guessing at the 1500KB mark...
-
Jan 10th, 2004, 06:30 PM
#9
Because the original code you have reads only 1500 KB.
Make a smaller buffer, read a block and write it out.
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);
?>
This should write out everything, no matter how large, in blocks of 4 KB.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Jan 10th, 2004, 06:42 PM
#10
Thread Starter
New Member
Sorry to annoy again but
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);
?>
doesnt work...least for me.
Last edited by x198; Jan 10th, 2004 at 06:46 PM.
-
Jan 10th, 2004, 06:43 PM
#11
You might have to change something about the while loop. Read up on file I/O, you should find the solution.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Jan 10th, 2004, 06:44 PM
#12
Thread Starter
New Member
u excluded a ')'
-
Jan 10th, 2004, 06:48 PM
#13
Don't blame me, it's 1AM here
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Jan 10th, 2004, 06:49 PM
#14
Thread Starter
New Member
It's the codes fault, it should have know about your inaccuracy!
6:50PM Eastern
-
Jan 10th, 2004, 06:52 PM
#15
Thread Starter
New Member
One more thing...
I wanted to use a variable for the site name, and this is what doesnt work
Code:
$sitenam="http://www.thegh.org";
$open = fopen($sitenam, "r");
NM stupid me forgot a ';' and PHP had a spaz attack
Last edited by x198; Jan 10th, 2004 at 07:00 PM.
-
Jan 10th, 2004, 06:57 PM
#16
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Jan 10th, 2004, 09:31 PM
#17
Thread Starter
New Member
Another error...
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);
why cant i do this?
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
Last edited by x198; Jan 10th, 2004 at 09:34 PM.
-
Jan 11th, 2004, 05:37 AM
#18
The site name must start with http://
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Jan 11th, 2004, 03:46 PM
#19
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:
PHP Code:
<?
function checkURL($url){
if(!substr($url, 0, 7) == "http://"){
return "http://" . $url;
}
}
//used like so:
$sitenam = checkURL($_POST['site']);
?>
It should work..
-
Jan 11th, 2004, 07:34 PM
#20
Thread Starter
New Member
Too many functions, AHHHH... ok, i'll try to use it, TY.
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.
-
Jan 11th, 2004, 08:50 PM
#21
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..
-
Jan 11th, 2004, 11:08 PM
#22
Stuck in the 80s
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|