Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 04-22-2008, 03:39 PM fwrite and include
Korzonek's Avatar
Skilled Talker

Posts: 60
Name: Michael
Location: Warsaw
Trades: 0
1.Is there any other way to write to a file? I generaly want to put stuff inside the file....in HERE I wanted to put: include ("something.php") so it would write templates in the newly created file...??

$file=fopen("$dt/$name","w");

fwrite($file,'HERE');

fclose($file);

please help
Korzonek is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 04-23-2008, 04:36 AM Re: fwrite and include
Super Spam Talker

Latest Blog Post:
PSD Squirrel Launched
Posts: 933
Trades: 7
Hi,

The best way to write text to a file is using file_put_contents() so try that one

Not sure what your asking about the include though?
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
Sir P is offline
Reply With Quote
View Public Profile Visit Sir P's homepage!
 
Old 04-23-2008, 09:44 AM Re: fwrite and include
Korzonek's Avatar
Skilled Talker

Posts: 60
Name: Michael
Location: Warsaw
Trades: 0
ok,different way

/*this creates a new file*/
$file=fopen("$dt/$name","w");

/*this file some variables that I want to put in it. In "HERE" I wanted to put for example header.php so the new file will be crated containing the header.php.*/
fwrite($file,'HERE');

fclose($file);

please help
Korzonek is offline
Reply With Quote
View Public Profile
 
Old 04-24-2008, 06:20 PM Re: fwrite and include
solomongaby's Avatar
Webmaster Talker

Latest Blog Post:
How Do You Find Music Online ?
Posts: 522
Name: Gabe Solomon
Location: Romania
Trades: 1
then you first need to read the content of header.php and then put that content in that file ...
if you want raw content use file function ... if you need parsed content you must use ob_start and ob_flush functions.
__________________
If you like my posts ... TK is appreciated:)

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
solomongaby is offline
Reply With Quote
View Public Profile Visit solomongaby's homepage!
 
Old 04-25-2008, 12:05 AM Re: fwrite and include
addonchat's Avatar
Super Talker

Posts: 115
Name: Chris Duerr
Trades: 0
Not sure if this helps, I used file_put_contents() below. You may need to use fopen,fwrite,fclose depending upon the version of PHP you're using.

PHP Code:
if( ($header_template file_get_contents('header.php.templ')) === FALSE
{
   echo 
"Read Error";
   die;
}

/* If you need to read in more files, such as a footer, it's the same.. */

if( ($footer_template file_get_contents('footer.php.templ')) === FALSE
{
   echo 
"Read Error";
   die;
}

/* Do your variable replacements using regular expressions or what have you on the template variables here and store the result in $content -- that is if that is what you're trying to do. */

if(file_put_contents("$dt/$name"$content)===FALSE
{
   echo 
"Error!";
   die;
}

/* If you need to append other data to your $dt/$name file, you can still use file_put_contents() */

file_put_contents("$dt/$name"'Hello, World!'FILE_APPEND);
file_put_contents("$dt/$name"$footer_contentFILE_APPEND); 
Most programs I see like this are run-time, so you'd be displaying the output instead of storing it to a file. In that case, output buffering may be important. I use scripts similar to the above for CLI side "compiling" of sites to update modified headers, or update copyright dates, cron tasks for scanning broken links, etc..
__________________
Chris Duerr
AddonChat Java Chat Software

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE
addonchat is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to fwrite and include
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.50981 seconds with 12 queries