By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,827 Members | 1,279 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,827 IT Pros & Developers. It's quick & easy.

how to fetch contents of external webpage and save it in txt file.

rishidadhich
P: 9
hello,
I am new to PHP,

I am stuccked in a problem that how to fetch text contents from a external website and then save them to a text file.

say there is any webpage www.xyz.com/index.html now i have to fetch all the text contents from the page index.html and have to save in a file.

I have no problem with XML or PAD formats but when it comes to HTML page I am Clueless..

can any body guide me through this.....

Thanx in advance..
Feb 9 '07 #1
Share this Question
Share on Google+
2 Replies


P: 99
try
[PHP]
$lineArray = file('http://www.test.com/');
foreach($lineArray as $line){
if(strlen($line) > 0){
echo strip_tags($line).'<br>';
}
}
[/PHP]

this way you have a line for every linebreak that exists in the file you try to retrieve.

Some site prevent scraping then you can try to use a socket connection
Feb 9 '07 #2

rishidadhich
P: 9
try
[PHP]
$lineArray = file('http://www.test.com/');
foreach($lineArray as $line){
if(strlen($line) > 0){
echo strip_tags($line).'<br>';
}
}
[/PHP]

this way you have a line for every linebreak that exists in the file you try to retrieve.

Some site prevent scraping then you can try to use a socket connection

hi xwero,
thanx for the suggestion, its working.

thanx again
Feb 10 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.