问题
Part of my PHP
code includes the construction of a URL
string as follows:
$msg = $_REQUEST["msg"];
$content = 'action=sendmsg'.
'&user='.rawurlencode($username).
'&password='.rawurlencode($password).
'&to='.rawurlencode($destination).
'&text='.rawurlencode($msg);
When $msg
happens to contain an apostrophe, it get sent as "\'"
.
What do I need to do to make sure the backslash is not inserted by PHP
?
回答1:
You probably want to check out stripslashes: http://php.net/manual/en/function.stripslashes.php
回答2:
Assume you want to send the $content
variable instead of just stripping the backslashes, Consider to use urlencode() instead of rawurlencode()
. Also, you can use the function once for your $content
variable.
$content = urlencode($content);
UPDATE: both urlencode
and rawurlencode
may not fit your case. Why don't you just send out the $content
without URL encode? How do you send our the query string? If you are using cURL, you do not need to encode the parameters.
回答3:
You can try
- Stipslashes
- or put the string in "" and add ' where you want.
来源:https://stackoverflow.com/questions/15331037/how-to-have-apostrophes-in-php-string