yanstv
yanstv

Reputation: 157

passing argument from bash file to php (long string with spaces)

I want to pass a text as a argument from a bash file to a php script like this:

bash script

#!/bin/sh

php /var/www/html/assets/sms/get_sms.php $SMS_1_NUMBER $SMS_1_TEXT

php script

<?php

$url = "http://localhost/user/user/get_sms/".$argv[1];    
$postdata = array('number' => $argv[1],'text'=>$argv[2]);
do_post_request($url,$postdata);

function do_post_request($url, $postdata)
{
  //My function
}
?>

The problem is that, the first argument to the bash file is a number but the second argument is text. The Php file which receives the arguments just takes the first string of the text. For example, if the text of the $SMS_1_TEXT variable is "How can I make it work" , the php file will receive only "How".

How can I make it woks better?

Thank you very much

Upvotes: 1

Views: 1642

Answers (1)

Cyrus
Cyrus

Reputation: 88829

Quoting. Replace $SMS_1_TEXT by "$SMS_1_TEXT".

Upvotes: 3

Related Questions