NArc0t1c Posted August 24, 2007 Share Posted August 24, 2007 Hello.. I'm trying to build an application that you will be able to replace things within a php file. I have built it, but I have a problem, it is not doing what it is supposed to. I have two array's, One with all the things that it should search for, and then one array that should be used for replacing. Here is a same: <?php $Search = array('<?pgp', ' <?php'); // 22 to be exact. $Replace = array('<?php', '<?php'); // 22 to be exact. ?> Well, I don't know if that is working or not, I suppose it is. The function I use for replacing is str_replace, It should search an array, and return the results as an array or string. Well, It's not doing either. Here is my script: <?php $Search = array('<?pgp', ' <?php'); // 22 to be exact. $Replace = array('<?php', '<?php'); // 22 to be exact. if (isset($_POST['submit'])){ $Random = md5(time()/rand(1,100)); // This would be the name of the file, I changed to test for this purpose. $Handle = fopen('attachments/test.txt', 'w+'); fputs($Handle, $_POST['code']); fclose($Handle); $File = file('attachments/test.txt'); $Files = str_replace($Search, $Replace, $File); $Handle = fopen('attachments/test.txt', 'w+'); foreach ($Files as $Lines){ fputs($Handle, $Lines); } fclose($Handle); } ?> I have cut it down and things but that is the principle it goes by. It's writing and things, but it would return the following in the text file: A And that's all. Anyone see anything I may be doing wrong? I have looked at the preg_replace function aswell, it did the same. Link to comment https://forums.phpfreaks.com/topic/66491-solved-replace/ Share on other sites More sharing options...
MadTechie Posted August 24, 2007 Share Posted August 24, 2007 change $File = file('attachments/test.txt'); to $File = file('attachments/test.txt'); $File = implode('', $File ); or file_get_contents($File); Link to comment https://forums.phpfreaks.com/topic/66491-solved-replace/#findComment-332930 Share on other sites More sharing options...
NArc0t1c Posted August 24, 2007 Author Share Posted August 24, 2007 No that doesn't work. Thanks anyway.. Link to comment https://forums.phpfreaks.com/topic/66491-solved-replace/#findComment-332931 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.