andytan91 Posted July 18, 2010 Share Posted July 18, 2010 Hello guys i am new to PHP. Basically what i am doing is an edit audit policy function. Basically the codes below are contained in a batch file. Users will run it in order to check whether he/she meets the requirement. If "Service Pack 2" is present, a pass notice will be given. What i want to do is to give system administrator the privilege to edit the audit policy, the argument to be changed will be located in findstr /C:"DEFINE ARGUMENT". I have managed to changed the file extension from .bat to .txt in order for php to read the text..now i need php to be able to edit the text in the DEFINE ARGUMENT part. Hence, if the system administrator inputs the desired text in an edit policy form, the text will replace the "Service Pack 2" in the text file. Ideas are welcome..thanks alot! @echo off systeminfo | findstr /C:"Service Pack 2" if %errorlevel%==0 ( echo Service_Pack_Requirement:Pass >> C:\final.doc ) else ( echo Service_Pack_Requirement:Fail >> C:\final.doc ) Link to comment https://forums.phpfreaks.com/topic/208102-edit-string-in-text-file-question/ Share on other sites More sharing options...
wildteen88 Posted July 18, 2010 Share Posted July 18, 2010 I have managed to changed the file extension from .bat to .txt in order for php to read the text PHP can read any text based file. There is no need to change the extension. What you'll want to do is first read the batch file $batch_file = 'filename.bat'; $batch_contents = file_get_contents($batch_file); Now to change the argument you'd use a small bit of regex $newArgument = 'NEW POLICY HERE'; $batch_contents = preg_replace('~findstr /C:"([a-z0-9_ -]+)"~i', 'findstr /C:"'.$newArgument.'"', $batch_contents); Lastly you'd rewrite the new contents to the batch file file_put_contents($batch_file, $batch_contents); Link to comment https://forums.phpfreaks.com/topic/208102-edit-string-in-text-file-question/#findComment-1087833 Share on other sites More sharing options...
andytan91 Posted July 19, 2010 Author Share Posted July 19, 2010 thanks bro i'll try it out later! Link to comment https://forums.phpfreaks.com/topic/208102-edit-string-in-text-file-question/#findComment-1087931 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.