ilikemath2002 Posted February 7, 2009 Share Posted February 7, 2009 I'm not sure if this goes here or not, but my last thread was moved here. How do I str_replace something IN a file? Link to comment https://forums.phpfreaks.com/topic/144231-solved-str_replace-in-a-file/ Share on other sites More sharing options...
landavia Posted February 7, 2009 Share Posted February 7, 2009 direct? no u cant if you want to change inside the text.. 1. load the file 2. change the content and save to variable $txt (example) 3. save the file using same filename Link to comment https://forums.phpfreaks.com/topic/144231-solved-str_replace-in-a-file/#findComment-756889 Share on other sites More sharing options...
.josh Posted February 7, 2009 Share Posted February 7, 2009 It depends on what your file looks like, as to how you would get the string to str_replace. Post an example of the file contents. Link to comment https://forums.phpfreaks.com/topic/144231-solved-str_replace-in-a-file/#findComment-756907 Share on other sites More sharing options...
ilikemath2002 Posted February 7, 2009 Author Share Posted February 7, 2009 The file is .htaccess anti-leech, normally I would just create the file AFTER I added the URL to anti-leech, but I thought this would be easier: In this file, I am trying to replace "replace" with a URL: RewriteEngine on RewriteCond %{HTTP_REFERER} !^http://(www\.)?replace/ [NC] RewriteRule \.(jpg|jpeg|png|gif|swf|bmp|ico|)$ - [NC,F,L] Maybe you can see how you helped me with the other thread(to CV). Link to comment https://forums.phpfreaks.com/topic/144231-solved-str_replace-in-a-file/#findComment-756909 Share on other sites More sharing options...
.josh Posted February 7, 2009 Share Posted February 7, 2009 $filename = 'path/to/filename'; $list = file($filename); // line in question is line 2 of file, so do replace on 2nd array element $list[1] = str_replace(....); file_put_contents($filename, $list); Link to comment https://forums.phpfreaks.com/topic/144231-solved-str_replace-in-a-file/#findComment-756922 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.