//code.txt
Expand|Select|Wrap|Line Numbers
- 101:2001
- 102:2002
- 103:2003
- 104:2004
[PHP]<?php
$code_file = 'code.txt';
$code_file_lines = file($code_file);
if(isset($_GET['address']) && isset($_GET['code'])){
$address = $_GET['address'];
$code = $_GET['code'];
$c = 0;
for($a = 0; $a<sizeof($code_file_lines); $a++){
$content = explode(":", $code_file_lines[$a]);
if($address == $content[0] && $code != $content[1]){
$code_content[$c] = trim($content[0]).':'.trim($code);
}else{
$code_content[$c] = trim($content[0]).':'.trim($content[1]);
}
$c++;
}
$new_code = implode('\n', $code_content);
file_put_contents($code_file, $new_code);
}
?>
[/PHP]
now if i try to send to send values like this to modify a certain line...
Expand|Select|Wrap|Line Numbers
- code_reader.php?address=102&code=2001
Expand|Select|Wrap|Line Numbers
- 101:2001
- 102:2001
- 103:2003
- 104:2004
Expand|Select|Wrap|Line Numbers
- 101:2001\n102:2001\n103:2003\n104:2004
[PHP]file_put_contents($code_file, $new_code);[/PHP]
will write it as string.. is there any function that will convert it to stream so that when it modifies the text file.. it can read "\n".
thanks..
bonski