In terminal how to pass a string as param that contains whitespace . It actually skips the part coming after whitespace and only takes the first word .
$word = 'soccer ball'
shell_exec('casperjs test.js --word='.$word);
So how can I escape the whitespace it only runs this command
casperjs test.js --word=soccer
For cases like the one you describe (there are other special characters next to space in shell), PHP has the escapeshellarg
function:
$word = 'soccer ball';
$command = sprintf('casperjs test.js --word=%s', escapeshellarg($word));
$result = shell_exec($command);
I takes care to preserve the value of $word
as one argument:
casperjs test.js --word='soccer ball'
See as well:
Try enclosing it in quotes:
casperjs test.js --word="soccer ball"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With