I'm writing a php script that will execute a bash script on the server. The one thing that is absolutely required for this exercise is that we're using /var/tmp/count.sh to get my data.
bash script:
#!/bin/bash
#filename: /var/tmp/count.sh
cat /etc/passwd | grep ':201:' | awk -F ':' '{print $1}'
#This command will spit out:
# user1
# user2
# user3
PHP Script:
<?php
$output = shell_exec('/var/tmp/count.sh');
$sizeofme = sizeof($output);
echo "$output" . "\n" ;
echo "sizeofme = $sizeofme" . "\n" ;
// this spits out:
// user1
// user2
// user3
// sizeofme = 1
?>
How do I make a PHP array that contains 3 elements?
A PHP equivielant of the following bash for loop:
for i in ${output[@]; do
newarray+=("$i")
done
Also, I noticed that if I do:
<?php
echo $output[0] . "\n" ;
echo $output[1] . "\n" ;
echo $output[2] . "\n" ;
echo $output[3] . "\n" ;
echo $output[4] . "\n" ;
echo $output[5] . "\n" ;
echo $output[6] . "\n" ;
echo $output[7] . "\n" ;
echo $output[8] . "\n" ;
echo $output[9] . "\n" ;
?>
I get:
u
s
e
r
1
u
s
e
r
2
... so on and so forth. What am I overlooking?