Hello guys im a newbie in php.. basically what i want to do it to print out the a certain string in a line. In this case, i want to retrieve out text that is after ":" and before policies.txt in the lines below for eg. Success or Failure. I think i would need preg_match function because i would need to print out the strings from multiple findstr commands. Ideas are welcome thanks! findstr /i /C:"User/Group Management : Success or Failure" policies.txt findstr /i /C:"Privileged Account Logon: Failure" policies.txt <?php $batch_file = 'audit_policy.bat'; $batch_contents = file_get_contents($batch_file); if (preg_match("/Privileged Account Logon:/i", "$batch_contents")) { echo "prints specific string here"; } else { echo "not found"; } ?> PHP:
Your descriptions vague so can't work-out what your looking for, but assuming your wanting to retrieve everything between two markers (after : and before policies.txt) try this: <?php $batch_file = 'audit_policy.bat'; $batch_contents = file_get_contents($batch_file); /* an attempt to make it generic */ $starting_marker = "Privileged Account Logon"; $ending_marker = "policies.txt"; if (preg_match('~'.preg_quote($starting_marker).'\s*:(.+?)'.preg_quote($ending_marker).'~i', $batch_contents, $a)) { echo $a[1]; } else { echo "not found"; } ?> PHP: