TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   General (http://www.talkphp.com/general/)
-   -   Read file and modify line by line before echo ?? (http://www.talkphp.com/general/5116-read-file-modify-line-line-before-echo.html)

Peuplarchie 11-16-2009 06:16 AM

Read file and modify line by line before echo ??
 
Good day to you all,

I'm working on a script wich permit me to read a file line by line and echo it.

Here is my code now:

PHP Code:


<?php

$console 
$_GET["console"];
$name $_GET["name"];


$file fopen("info_gen.txt""r") or exit("Unable to open file!");
//Output a line of the file until the end is reached
while(!feof($file))
  {
  echo 
fgets($file). "<br />";
  }
fclose($file);
?>


My problem is I need to be able to add or edit each and every line seperatly and differently before echo everyting.

How can I do so ?

Thanks!

maeltar 11-16-2009 07:54 AM

Hey there,

So basically you are wanting an online file editor ? (thats the way I understand it)

Have a look

http://www.hotscripts.com/listing/si...p-file-editor/

or

http://www.dreamincode.net/code/snippet99.htm

tony 11-16-2009 03:20 PM

why not use the file or file_get_contents functions.

php Code:
<?php
$file = file("info_gen.txt");
$output = '';
foreach ($file as $line_num => $line) {
    //do something to the line
    $output = "#<b>{$line_num}</b> : "$line."<br />\n";
}
//then echo the output
echo output;
?>

I haven't tested this code, but I think those functions would be better to use.


All times are GMT. The time now is 02:37 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0