| | |
php file append
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Apr 2009
Posts: 19
Reputation:
Solved Threads: 0
have this script
trying to write "<?php \$lastid = \"$lastid\"; ?>"; in the first line of the file but what is happening is its deleting some of my code in the file. any way that you can skip a line or someting to preserve the coding that is already in the filename ?
PHP Syntax (Toggle Plain Text)
$idhandle = fopen($filename, 'r+') or die("can't open file"); $id = "<?php \$lastid = \"$lastid\"; ?>"; fwrite($idhandle, $id); fclose($idhandle);
trying to write "<?php \$lastid = \"$lastid\"; ?>"; in the first line of the file but what is happening is its deleting some of my code in the file. any way that you can skip a line or someting to preserve the coding that is already in the filename ?
Starting with the obvious, why are you using:
instead of:
PHP Syntax (Toggle Plain Text)
$id = "<?php \$lastid = \"$lastid\"; ?>";
instead of:
PHP Syntax (Toggle Plain Text)
$id = $lastid;
If you are trying to send php code to the file then perhaps it is better to use single quotes like the following so variables inside the string do not display their values:
Or if you just want the value of the second variable substituted with its value while the first variable stays as it is:
Or if you want all of the variable names substituted with their values
It is unclear exactly what result you want in the text file but I hope the above examples help solve the question.
php Syntax (Toggle Plain Text)
$idhandle = fopen($filename, 'r+') or die("can't open file"); $id = '<?php $lastid = "$lastid"; ?>'; fwrite($idhandle, $id); fclose($idhandle);
php Syntax (Toggle Plain Text)
$id = '<?php $lastid = "'.$lastid.'"; ?>';
php Syntax (Toggle Plain Text)
$id = "<?php $lastid = \"$lastid\"; ?>";
Try not to bump 10 year old threads as it can be really annoying.
http://syntax.cwarn23.net/
My favourite PC. - MacGyver Fan
http://syntax.cwarn23.net/
Smilies: ^_* +_+ v_v -_- *~*` My favourite PC. - MacGyver Fan
![]() |
Similar Threads
- Php question (PHP)
- Send form results to a .txt file (PHP)
- Generating an excel file. (PHP)
- PHP query CSV (PHP)
- How to insert new argument into the middle of a file (Shell Scripting)
- Python and the JPEG Image File, Part 2, The Image (Python)
- Python and the JPEG Image File, Part 1, The Header (Python)
- file query (C++)
- libtiff (C++)
Other Threads in the PHP Forum
- Previous Thread: Dates in drop down box
- Next Thread: dynamic Links Help!!! please
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess access ajax apache api array beginner binary broken cakephp checkbox class cms code confirm cron curl customizableitems database date directory display download dynamic echo email error external file files folder form forms forum function functions google headmethod href htaccess html iframe image include insert integration ip java javascript joomla limit link login loop mail malfunction menu mlm mod_rewrite multiple mysql oop parse paypal pdf php play problem query question radio random recursion regex remote script search server sessions shopping sms soap source space sql structure syntax system table tutorial update upload url validation validator variable video web xml youtube






