Regular Expression

Discussion in 'PHP' started by andytan91, Jul 21, 2010.

  1. #1
    Hello guys i would like to replace the string in this line -> $batch_file1 = 'service_pack.bat'; It is located on another php file. I have tried doing it for an hour but to no avail, can someone guide me? Thanks!

    <?php

    $file = 'C:\xampp\htdocs\new\editpolicy.php';
    $batch_contents = file_get_contents($file);

    if(isset($_POST['argument']) && $_POST['submit'] == "Save")
    {

    $newArgument = $_POST['argument'];

    preg_replace('~$\batch_file1 = "([a-z0-9_ -]+)"~i', '$\batch file1 = "'.$newArgument.'"' ,$batch_contents);
    }file_put_contents($file, $batch_contents);

    ?>


    <b>Deploy Service Pack Policy</b>
    <p>
    <form action="deploy.php" method="post">
    Select audit file to deploy: <input type="text" name="argument"<br>
    <input type="submit" name="submit" value="Save"> &nbsp;<p>
    </form>
    </p>
     
    Last edited: Jul 21, 2010
    andytan91, Jul 21, 2010 IP
  2. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #2
    <?php
    $file = 'C:\xampp\htdocs\new\editpolicy.php';
    $batch_contents = file_get_contents($file); 
    if (isset($_POST['argument']) && $_POST['submit'] == "Save") {
    $batch_contents = preg_replace('~\$batch_file1\s*=\s*"(.+?)"~i', '$batch_file1 = "'.$newArgument.'"', $batch_contents);
    file_put_contents($file, $batch_contents);
    }
    ?>
    PHP:
     
    danx10, Jul 21, 2010 IP
  3. andytan91

    andytan91 Greenhorn

    Messages:
    25
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #3
    thanks bro!
     
    andytan91, Jul 21, 2010 IP