CoreyR Posted June 23, 2007 Share Posted June 23, 2007 I have a text file which contains "&" and I'm trying to figure out how to replace the string with & and re-write the file. Any ideas or resources you know of would be appreciated. Corey R. Link to comment https://forums.phpfreaks.com/topic/56901-replace-string-in-file/ Share on other sites More sharing options...
aim25 Posted June 24, 2007 Share Posted June 24, 2007 Use the str_replace function. Link to comment https://forums.phpfreaks.com/topic/56901-replace-string-in-file/#findComment-281125 Share on other sites More sharing options...
CoreyR Posted June 24, 2007 Author Share Posted June 24, 2007 What am I doing wrong here? $filename = "/htdocs/www/vmware/$username/index.php"; $fh = fopen($filename, 'r+') or die("can't open file"); foreach ($filename as $line) { str_replace("&", "&", $line); } $htmldata = $line_num; fwrite($fh, $htmldata); fclose($fh); Link to comment https://forums.phpfreaks.com/topic/56901-replace-string-in-file/#findComment-281128 Share on other sites More sharing options...
aim25 Posted June 24, 2007 Share Posted June 24, 2007 Im pretty sure that it's because $filename isnt a string. Link to comment https://forums.phpfreaks.com/topic/56901-replace-string-in-file/#findComment-281129 Share on other sites More sharing options...
aim25 Posted June 24, 2007 Share Posted June 24, 2007 Use file_get_contents, to make the file into a string. Link to comment https://forums.phpfreaks.com/topic/56901-replace-string-in-file/#findComment-281131 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.