-   Linux - Server (
-   -   trying to append data to a file with php/fwrite (

steve51184 08-16-2010 08:13 PM

trying to append data to a file with php/fwrite
hi all i'm trying to make a quick and simple '.htaccess' installer and i'm using fopen/fwrite to do this but i'm getting an error:


Parse error: parse error in /var/www/test.php on line 12
here's the code:


$File = ".htaccess";
$fh = fopen($File, 'a');
$Data = "\n#test write
<IfModule mod_deflate.c>
  AddOutputFilterByType DEFLATE text/css
  AddOutputFilterByType DEFLATE text/javascript application/javascript application/x-javascript text/x-js text/ecmascript application/ecmascript text/vbscript text/fluffscript
  AddOutputFilterByType DEFLATE image/svg+xml application/x-font-ttf application/x-font font/opentype font/otf font/ttf application/x-font-truetype application/x-font-opentype application/ application/vnd.oasis.opendocument.formula-template
  AddOutputFilterByType DEFLATE text/xml application/xml
<IfModule mod_expires.c>
<FilesMatch "\.(ico|gif|jpg|JPG|jpeg|png|PNG|swf|css|js|html?|xml|txt)$">
ExpiresActive On
ExpiresDefault "access plus 1 month"
#test write\n";
fwrite($fh, $Data);

how do i include the code in the $Data string bit?

jlinkels 08-16-2010 08:29 PM

You have quotes embedded in your string. Therefor PHP considers the string as terminated.


<FilesMatch "\.(ico|gif|jpg|JPG|jpeg|png|PNG|swf|css|js|html?|xml|txt)$">
You must escape every quote:

<FilesMatch \"\.(ico|gif|jpg|JPG|jpeg|png|PNG|swf|css|js|html?|xml|txt)$\">
I did not check them all.


steve51184 08-16-2010 08:35 PM

perfect thank you

All times are GMT -5. The time now is 06:00 PM.