Crmgo Blog

PHP, example of interaction with the command line

PHP, example of interaction with the command line

<div align="center" style="margin-top: 100px; border: 1px solid; width: 500px; padding-top: 9px;"> <form method="post" action="search.php?action=complited"> <input type="text" name="text" size="40"> <input type="submit" value="grep"> </form> <?php if ($_SERVER['REQUEST_URI']=='/search.php?action=complited'){ echo '<pre>'; // Outputs the entire result of the shell command "ls", and returns // the last line of output to…

PHP, example of interaction with the command line

<div align="center" style="margin-top: 100px; border: 1px solid; width: 500px; padding-top: 9px;">
<form method="post" action="search.php?action=complited">
<input type="text" name="text" size="40">
<input type="submit" value="grep">
</form>
<?php
if ($_SERVER['REQUEST_URI']=='/search.php?action=complited'){
echo '<pre>';

// Outputs the entire result of the shell command "ls", and returns
// the last line of output to the variable $last_line. Saves the return code
// of the shell command to $retval.
$last_line = system('grep -lr "'.$_POST['text'].'" ./', $retval);
//$last_line = system('ls', $retval);
// Outputs additional information
echo '</pre>';
}
?>
</div>

Note: This post may be AI-assisted and then human-edited. Editorial responsibility: Dmytro Lomaka, Kaltenkirchen.

Categories: PHP