Ell20 Posted December 5, 2007 Share Posted December 5, 2007 Hi, I have a messaging system where players can message each other in the game. However if a player sends a message which contains --> there inbox dosent display correctly. The code which sends the message to the database is: $mailtext = addslashes(strip_tags($_POST['chat'])); Has anyone got any idea what I can do to stop this happening? I have tried: - $mailtext = stripslashes(strip_tags($_POST['chat'])); - $mailtext = stripslashes(trim($_POST['chat'])) But none of these combinations solved the problem. Thanks for any help Elliot Link to comment https://forums.phpfreaks.com/topic/80345-solved-messing-up-php/ Share on other sites More sharing options...
Guest Posted December 5, 2007 Share Posted December 5, 2007 Try using htmlentities($_POST['chat'], ENT_QUOTES) for when it's displayed on a page, and use mysql_real_escape_string() when you are putting it into the db. Addslashes lull developers into a false sense of security in this respect. Link to comment https://forums.phpfreaks.com/topic/80345-solved-messing-up-php/#findComment-407216 Share on other sites More sharing options...
kenrbnsn Posted December 5, 2007 Share Posted December 5, 2007 If you're sending the inputted text to a browser, you want to use the function htmentities() with the ENT_QUOTES option, not addslashes. Ken Link to comment https://forums.phpfreaks.com/topic/80345-solved-messing-up-php/#findComment-407217 Share on other sites More sharing options...
Ell20 Posted December 5, 2007 Author Share Posted December 5, 2007 So something like this: $mailtext = htmentities(ENT_QUOTES($_POST['chat'])); Thanks Link to comment https://forums.phpfreaks.com/topic/80345-solved-messing-up-php/#findComment-407219 Share on other sites More sharing options...
Guest Posted December 5, 2007 Share Posted December 5, 2007 So something like this: $mailtext = htmentities(ENT_QUOTES($_POST['chat'])); Thanks ENT_QUOTES isn't a function, its a constant. It's meant to be used as such: $text = htmlentities($_POST['chat'], ENT_QUOTES); Also, to clarify, it's htmlentities, not htmentities (the L is crucial) Link to comment https://forums.phpfreaks.com/topic/80345-solved-messing-up-php/#findComment-407221 Share on other sites More sharing options...
Ell20 Posted December 5, 2007 Author Share Posted December 5, 2007 thanks very much for your help, solved! Link to comment https://forums.phpfreaks.com/topic/80345-solved-messing-up-php/#findComment-407231 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.