PHP string variable and string

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
huyga1982
Forum Newbie
Posts: 2
Joined: Fri Apr 27, 2007 2:13 am

PHP string variable and string

Post 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.
huyga1982
Forum Newbie
Posts: 2
Joined: Fri Apr 27, 2007 2:13 am

thank you, i've done it.

Post 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:
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

escapeshellcmd() may be a better choice.
Post Reply