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"> <p> </form> </p>
<?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: