legacyblade Posted July 13, 2010 Share Posted July 13, 2010 Hello. My employer contracted me to make a web script that replaces certain items of text in an HTML document (the name, contact e-mail, etc). It's all very well and good, and functioning. Except for one error I didn't realize until the final testing. One thing that my script is replacing is a bit of the HTML code for an e-mail optin form. The script passes no errors when HTML is given to it as a string, but it refuses to replace properly. After some experimenting, I found that the problem is this: anything after a < doesn't show up in a string. Anything else (even ',",\ or other special characters) show up just fine as a character in the string. But anything after the first instance of a < is not included in the string (and when the whole string is HTML code, that doesn't work very well). I've even tried passing \<, but that just makes the value of the string "\". Does anyone know how to get around this problem? Link to comment https://forums.phpfreaks.com/topic/207632-html-code-input-from-form-problems/ Share on other sites More sharing options...
rondog Posted July 13, 2010 Share Posted July 13, 2010 I dont think you can escape that character, but rather replace it with < Link to comment https://forums.phpfreaks.com/topic/207632-html-code-input-from-form-problems/#findComment-1085449 Share on other sites More sharing options...
rondog Posted July 13, 2010 Share Posted July 13, 2010 and actually I just found this which might be helpful: http://php.net/manual/en/function.htmlspecialchars.php Link to comment https://forums.phpfreaks.com/topic/207632-html-code-input-from-form-problems/#findComment-1085450 Share on other sites More sharing options...
legacyblade Posted July 13, 2010 Author Share Posted July 13, 2010 Thanks! That gives me a great step in the right direction. Typing in < instead of < works. However, I'm not quite sure how to replace the <s from a textarea (they paste in the HTML) with a < Any suggestions? Link to comment https://forums.phpfreaks.com/topic/207632-html-code-input-from-form-problems/#findComment-1085451 Share on other sites More sharing options...
legacyblade Posted July 14, 2010 Author Share Posted July 14, 2010 bump. I still have a problem. I'd try replacing every instance of < in the string with <, but that character ends the string. < and anything after it are considered not in the string. So I'm not quite sure how to go about fixing it. I'm getting the input from a textarea that's being submitted via ah html form. Any suggestions? Link to comment https://forums.phpfreaks.com/topic/207632-html-code-input-from-form-problems/#findComment-1085883 Share on other sites More sharing options...
kenrbnsn Posted July 14, 2010 Share Posted July 14, 2010 Use htmlentities on the string when you display it. Ken Link to comment https://forums.phpfreaks.com/topic/207632-html-code-input-from-form-problems/#findComment-1085890 Share on other sites More sharing options...
legacyblade Posted July 14, 2010 Author Share Posted July 14, 2010 Worked perfectly, thanks Link to comment https://forums.phpfreaks.com/topic/207632-html-code-input-from-form-problems/#findComment-1085937 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.