Forum Moderators: coopster

Message Too Old, No Replies

addcslashes

I'm not sure how to use it...

         

mechanical messiah

8:43 pm on Jun 5, 2004 (gmt 0)

10+ Year Member



I've looked up the addcslashes function several time, but haven't had any luck figuring out how it works.

What I'm trying to do is escape any characters that will cause errors in the linux shell, because the program makes use of the shell_exec function.

I've figured on the following characters being exited:

. + *? [ ^ ] ( $ ) ' " \ NUL &

Using more than one function will cause conflicts (i.e. addslashes() mixed with quotemeta() causes problems). To solve this, I've decided to use addcslashes and specify each of the above characters. Because I have characters in the list that will mess up even the function, I don't know how to tell the function that I want them exited other than with their ASCII codes, but I'm not sure how to enter ASCII codes. I have the codes for the desired characters, just don't know how to put the function.

Would it be like this?

addcslashes("$var", "\0\34\36\38\39\etc...");

coopster

5:49 pm on Jun 7, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Yes, I believe so, except I think it is going to want the octal value, not the decimal:
addcslashes($var, "\000\042\044\046\047");
the leading zero(s) could be dropped and you'll get the same result

[asciitable.com...]

Note:
The manual states to use the ord() function to get the ASCII value for a character, however when I tested this on a WAMP setup, addcslashes did not work until I used the octal value...anyone else have insight here...?