How to write into file on perfect position

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Naeem
Forum Commoner
Posts: 31
Joined: Tue Jul 07, 2009 12:48 pm

How to write into file on perfect position

Post by Naeem »

I have file like this:

Code: Select all

<?php
$database = "Writing Text here";
 
I want to that when user submit input it's write into $database = "writing text here"; using fwrite function how to do that?
Thanks.
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: How to write into file on perfect position

Post by onion2k »

If that's the entire file then it's probably easiest just to rewrite the whole thing. Eg

Code: Select all

fputs($file, "<?php\n\$database = \"".$value."\";");
Naeem
Forum Commoner
Posts: 31
Joined: Tue Jul 07, 2009 12:48 pm

Re: How to write into file on perfect position

Post by Naeem »

No it's not a entire file i just want to write the input data here only:

Code: Select all

$database = "Writing Text here"
Post Reply