Reputation: 15
I have a chat that uses ajax to send messages to the server. My problem is that when the user tries to send a hashtag, everything after the hashtag is omitted. I saw a similar question like this that said encoding would help. I tried encoding it, but it created bigger problems when it got to the php. It started counting the + sign as a space and made the first two numbers after a % sign go missing. Is there a workaround to this in php, or should I try something other than encoding.
here is the relevant javascript with the encoding.
ajax.open("GET", "/chatAdd.php?msg=" + encodeURIComponent(message.value) + "&user=" + encodeURIComponent(user) + "&id=" + encodeURIComponent(id));
And the php i used to decode it.
$user = urldecode($_REQUEST["user"]);
$userID = urldecode($_REQUEST["id"]);
$msg = urldecode($_REQUEST["msg"]);
Upvotes: 1
Views: 1482
Reputation: 1386
Use Percent encoding. Replace the hash with %23.
Edit: Also, a really great resource for escaping in JS and PHP - http://www.the-art-of-web.com/javascript/escape/
Upvotes: 2