FRIHOSTFORUMSSEARCHFAQTOSBLOGSCOMPETITIONS
You are invited to Log in or Register a free Frihost Account!


PHP Write to line





caiba
OK.. i aint bin here for a while and this place has grown.... does anyone now if its possible to do a php script to write to a file on a certain line if u understand me
napoleonvn
caiba wrote:
OK.. i aint bin here for a while and this place has grown.... does anyone now if its possible to do a php script to write to a file on a certain line if u understand me

I don't understand your question exactely but if you want to write a line with php ,view example script below:
<?php
@$f=fopen("yourfile.txt","w");/* This line will open the file yourfile.txt if it is not available will create it*/
fwrite($f,"your text here");
fclose($f);
?>
Slay
napoleonvn wrote:
caiba wrote:
OK.. i aint bin here for a while and this place has grown.... does anyone now if its possible to do a php script to write to a file on a certain line if u understand me

I don't understand your question exactely but if you want to write a line with php ,view example script below:
<?php
@$f=fopen("yourfile.txt","w");/* This line will open the file yourfile.txt if it is not available will create it*/
fwrite($f,"your text here");
fclose($f);
?>

there are 3 modes to open a file
"r" read
"w" write ==> it will delete your old file and create a new one !!
"a" append => try to open the file and create if not exist.
you have got fseek to move into your file.
but i recommend you to have a look in http://www.php.net/
the666bbq
there is no built-in way to write to a specific line in php. Probably the easiest way to achieve this is :

a) read the file you already have into an array with $arr = file($file);
b) cut the array into two arrays based on the line you want to write to
c) make the final array as the combination of part one, the new line, part two
d) clear the file
e) loop through the final array and write every item of the array as a new line.

if you are not confident with it skip d) and write the array content to a temp file to compare the outcome
Related topics
How To : Secure Your PHP Website
[PhP] News Posting Tutorial (code, actually ^^')
PHP DB Error: syntax error
Fatal PHP error
uma grande dúvida em php, por favor me ajudem
PHP script has MSQL access denied
[PHP] Error link
[Resolved] Object Orientated PHP errors
PHP Login Problem
PHP/Blogger error
PHP include code problem
Anyone Using Simple PHP Blog
Problem with write perimissions.
Open, Write to and Close a txt file using php
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.