1

I'm actually trying to "create" a script file (like script.sh) with php.

I get phone number by php request on previous page.

I got the script working in runscript but i need it to be "dynamic", so here is a part of my script working in bash :

$tel = 34000000000    
echo "\"OK\"" > /script_minicom/script_$tel   
echo "send AT+CMGS=\"+$tel\" \r" >> /script_minicom/script_$tel

Here is the output :

"OK"
send AT+CMGS="+34000000000" \r

Name of the file

/script_minicom/script_34000000000

But i need it working with PHP (to get phone number) so i'm trying this :

$tel = $_POST['tel'];
exec("echo '\"OK\"' > /script_minicom/script_$tel");
exec("echo send AT+CMGS=\"+$tel\" '\r' >> /script_minicom/script_$tel");

It works for the first line but the 2nd make my "\r" disapear and $tel isn't surrounded by quotes (can't work wihtout them) :

"OK"
send AT+CMGS=+34000000000

Name of the file :

/script_minicom/script_34000000000
arow
  • 13
  • 2

1 Answers1

1

\r inside double quotes gets interpolated as a carriage return in PHP. Use single quotes around it

exec("echo send AT+CMGS=\"+$tel" .'" \r'. " >> /script_minicom/script_$tel");

Output

send AT+CMGS="+34000000000" \r
Hanky Panky
  • 46,730
  • 8
  • 72
  • 95
  • Well it doesn't works at all "error 500 internal error", i've tried to change .'" \r'. " by a lot of things but still not working. So i've add a line after echo send AT+CMGS=\"+$tel\" echo send '\r' – arow Nov 26 '15 at 09:56
  • It works absolutely fine for me: https://eval.in/476420 . However if it doesn't work for you there is no need to accept this as an answer cause it will be misleading for future readers – Hanky Panky Nov 26 '15 at 12:53