Log in

View Full Version : scanning a .txt webpage and converting to a variable.



james438
08-29-2007, 03:32 AM
How could I create a form where I enter in the url of a txt document, which would then retrieve the text from that document and save it as a string to be manipulated for my own diabolical plans?

Sort of like how W3C scans a web page for errors, except that I have different plans. The format would be simple like $text="everything from selected www.a_site.txt"

I can create a form and manipulate the data, but getting it from a submitted url is where I am unsure.

thetestingsite
08-29-2007, 03:35 AM
Well, you could use fopen() (http://www.php.net/fopen) or file_get_contents() (http://www.php.net/file_get_contents), but this requires that your server has "allow_url_fopen" set in the php.ini file. If you cannot use those options, then you will have to use fsockopen() (http://www.php.net/fsockopen) and do it the old fashioned way.

Hope this helps.

james438
08-29-2007, 05:45 AM
Took me a bit to figure it how it works, but both fopen() and file_get_contents() worked for me :)


<?php
$handle = file_get_contents("http://www.animeviews.com/test_text.txt",NULL);
echo htmlentities($handle);
?> is mostly what I am going to use. I am using this to help out lindm in thread (http://www.dynamicdrive.com/forums/showthread.php?t=24059). I feel like I am working on a crossword puzzle and asking everyone what 6 across or 4 down is :p. Still, I am learning a lot and having too much fun :)