<?php
//-i means ignore case
$users = `grep -i smith /var/www/html/php-books/php-and-mysql-web-development/chapter15/executing-commands-pag-353/phonenums.txt`;
//split the output lines into an array
//note that the \n should be \r\n on Windows;
$lines = preg_split("/\n/",$users);
foreach ($lines as $line){
//name and phone nums are separated by, char
$namenum = preg_split(',',$lines);
echo "Name: {$namenum[0]},Phone #: {$namenum[1]}<br/>\n";
}
?>
in the file phonenums.txt
there is
smith,699457830
albert,34678912
Fatal error: Uncaught TypeError: preg_split(): Argument #2 ($subject) must be of type string, array given in /var/www/html/php-books/php-and-mysql-web-development/chapter15/executing-commands-pag-353/executing-commands.php:11 Stack trace: #0 /var/www/html/php-books/php-and-mysql-web-development/chapter15/executing-commands-pag-353/executing-commands.php(11): preg_split(',', Array) #1 {main} thrown in /var/www/html/php-books/php-and-mysql-web-development/chapter15/executing-commands-pag-353/executing-commands.php on line 11
the path is correct is working with the linux terminal
grep -i smith /var/www/html/php-books/php-and-mysql-web-development/chapter15/executing-commands-pag-353/phonenums.txt
return smith,699457830