Jump to content

[SOLVED] Replace


NArc0t1c

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.