1

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?

CJ7
  • 22,579
  • 65
  • 193
  • 321

3 Answers3

3

You probably want to check out stripslashes: http://php.net/manual/en/function.stripslashes.php

Eli White
  • 1,014
  • 1
  • 10
  • 20
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.

Raptor
  • 53,206
  • 45
  • 230
  • 366
1

You can try

  1. Stipslashes
  2. or put the string in "" and add ' where you want.