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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.