Drongo_III Posted May 23, 2011 Share Posted May 23, 2011 Hi Guys Simple question. Can anyone tell me why this doesn't work please? $test = "<HEELOOOO"; $test2 = filter_var("$test", FILTER_SANITIZE_STRING); echo $test2; When I run this get I get nothing echoed back, not even in the source. So can the filter function not be used like this? I thought it would encode the special character and return it but I must be missing something simple here! Thanks, Drongo Quote Link to comment https://forums.phpfreaks.com/topic/237225-simple-validation-functions/ Share on other sites More sharing options...
Adam Posted May 23, 2011 Share Posted May 23, 2011 You're getting an empty string back because the opening "<" is making PHP think it's a HTML tag. If you want to encode the characters you should use htmlspecialchars or htmlentities - filter_var() will filter it out completely. Quote Link to comment https://forums.phpfreaks.com/topic/237225-simple-validation-functions/#findComment-1219099 Share on other sites More sharing options...
Drongo_III Posted May 23, 2011 Author Share Posted May 23, 2011 ooooooh...that makes a lot more sense! Just tried it with a longer string enclosing the tags and it works. TY Quote Link to comment https://forums.phpfreaks.com/topic/237225-simple-validation-functions/#findComment-1219104 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.