We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,608 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

file_get_contents then write to text file

Im grabbing a page with below.

$homepage = file_get_contents('http://www.example.com/');
echo $homepage;

How do I write it to a file.txt and overwite in the event the file exists ?

Thanks.

2
Contributors
2
Replies
1 Hour
Discussion Span
8 Months Ago
Last Updated
3
Views
Question
Answered
reco21
Light Poster
43 posts since Jan 2011
Reputation Points: 14
Solved Threads: 1
Skill Endorsements: 0

@reco21

Did you read and check the manual:

http://php.net/manual/en/function.file-get-contents.php

-

<?php 

$homepage = file_get_contents('http://www.example.com/');

$filename = $homepage.'\example.txt';

$handle = fopen($filename,"x+");

$somecontent = "";

fwrite($handle,$somecontent);

echo "Success";

fclose($handle);

?> 
LastMitch
Industrious Poster
4,118 posts since Mar 2012
Reputation Points: 132
Solved Threads: 334
Skill Endorsements: 45

thank you. Yeah I was caught up on file_put_contents. Thanks again.

reco21
Light Poster
43 posts since Jan 2011
Reputation Points: 14
Solved Threads: 1
Skill Endorsements: 0
Question Answered as of 8 Months Ago by LastMitch

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0629 seconds using 2.67MB