Latest LQ Deal: Linux Power User Bundle
Go Back > Forums > Linux Forums > Linux - Server
User Name
Linux - Server This forum is for the discussion of Linux Software used in a server related context.


  Search this Thread
Old 08-16-2010, 09:13 PM   #1
Registered: Dec 2006
Posts: 379

Rep: Reputation: 30
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?
Old 08-16-2010, 09:29 PM   #2
Senior Member
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 4,792

Rep: Reputation: 799Reputation: 799Reputation: 799Reputation: 799Reputation: 799Reputation: 799Reputation: 799
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.

Old 08-16-2010, 09:35 PM   #3
Registered: Dec 2006
Posts: 379

Original Poster
Rep: Reputation: 30
perfect thank you


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Does fwrite() write entire file on jffs2? bjj2282 Linux - Software 0 10-26-2007 11:03 AM
Slow file writing with 'fwrite' function in C-code... scho Programming 5 08-07-2006 01:42 AM
c++ append data to file blizunt7 Programming 3 07-04-2005 01:47 AM
inserting the data thru php in a text file suchi_s Programming 5 02-02-2005 04:28 AM
radius append/add data ethanchic Linux - Software 0 04-16-2003 03:05 AM > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 09:16 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration