andz Posted July 2, 2010 Share Posted July 2, 2010 Hi Is there a way to edit a a string in a textfile? For now, I only have the codes to write to a file. I also want to be able to edit the content of the .htaccess let say i will comment something like commenting the RewriteRule string. Is that possible? The code below only works in appending ErrorDocument string on the existing .htaccess. $htaccess = file_get_contents('.htaccess'); if (!preg_match('/^ErrorDocument 404 /', $htaccess, $matches)) { # create htaccess file $fp = fopen('.htaccess', 'a'); if ($fp) { $str = 'ErrorDocument 404 '.$url; fwrite($fp, $str); } fclose($fp); } Link to comment https://forums.phpfreaks.com/topic/206525-edit-string-in-a-htaccess/ Share on other sites More sharing options...
AbraCadaver Posted July 2, 2010 Share Posted July 2, 2010 Read the file into a string with file_get_contents(), make changes to the string and then write it back out with file_put_contents(). Link to comment https://forums.phpfreaks.com/topic/206525-edit-string-in-a-htaccess/#findComment-1080424 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.