Page 1 of 1

PHP string variable and string

Posted: Fri Apr 27, 2007 2:28 am
by huyga1982
hi *,
i have a problems in string. i want to exec a shell command from php. when i want to change password of user the shell command is
if password is x'>
./pwdsync.sh 'local001' 'x'\''>'
if password is '
./pwdsync.sh 'local001' \'
and code in php
$txtpwd = str_replace("'","'\'\\\'\''",$txtpwd);
exec('/opt/ua/sh/pwdsync.sh \'' . $mnid . '\' \'' . $txtpwd . '\'');
but i can't do it successful. if i use
exec('/opt/ua/sh/pwdsync.sh \'' . $mnid . '\' \'' . '\'\\\'\'' . '\'');
the password change to ' successfully. and when i echo txtpwd, it's not match with the string i assigned.
plz, help me.

thank you, i've done it.

Posted: Fri Apr 27, 2007 3:14 am
by huyga1982
thank you *, i've done it. and now i having coffe and tabaco with a smiling face.
i use this command to make it works.
$txtpwd = str_replace(chr(39),chr(39).'\\'.chr(39).chr(39),$txtpwd);
exec('/opt/ua/sh/pwdsync.sh \'' . $mnid . '\' \'' . $txtpwd . '\'');
:roll:

Posted: Sat Apr 28, 2007 11:27 am
by feyd
escapeshellcmd() may be a better choice.