Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Jun 2010
    Posts
    132
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Automatically Replace

    I have an xml file, I want to replace every word that is "example1" and replace them with "example2". I do not want to edit the original file, I want to make a new file from it and this new file will have "example2" words (that replaced "example1") on it
    (Any Suggestions Will be Helpfull)

  • #2
    Regular Coder poyzn's Avatar
    Join Date
    Nov 2010
    Posts
    266
    Thanks
    2
    Thanked 61 Times in 61 Posts
    PHP Code:
    $file1 file_get_contents('path/to/file1');
    $file2 preg_replace('/example1/m''example2'$file1);
    file_put_contents('/path/to/file2'$file2); 
    Last edited by poyzn; 12-02-2010 at 03:38 PM.

  • #3
    Super Moderator
    Join Date
    Feb 2009
    Location
    England
    Posts
    539
    Thanks
    8
    Thanked 63 Times in 54 Posts
    I answered this, in full, with working code at: http://www.codingforums.com/showthread.php?t=210761

    If it didn't do quite what you wanted, perhaps continue that thread? Otherwise people will just be reinventing the wheel.
    lamped.co.uk :: Design, Development & Hosting
    marcgray.co.uk :: Technical blog

  • #4
    Regular Coder
    Join Date
    Jun 2010
    Posts
    132
    Thanks
    8
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Lamped View Post
    I answered this, in full, with working code at: http://www.codingforums.com/showthread.php?t=210761

    If it didn't do quite what you wanted, perhaps continue that thread? Otherwise people will just be reinventing the wheel.
    Ok, You are right but I want another method, other that simple xml... I want it php


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •