Taffd Posted November 28, 2007 Share Posted November 28, 2007 Hi all, Can anybody tell me why this simple regex doesn't work $comment = htmlentities($_POST['comment']); if (preg_match("/</", $comment)) { print 'string is NOT OK!'; } else { print 'string is OK!'; } This if statement works if I substitute < with another character. I'm confused Quote Link to comment Share on other sites More sharing options...
Orio Posted November 28, 2007 Share Posted November 28, 2007 What do you mean by "if statement works"? Are you getting "string is NOT OK"? Orio. Quote Link to comment Share on other sites More sharing options...
Taffd Posted November 28, 2007 Author Share Posted November 28, 2007 No. When I use the character <, "I get string is ok". However if I substitute , with A, then inputting A as $comment, gives me "string is not ok". ie it works. Quote Link to comment Share on other sites More sharing options...
Orio Posted November 28, 2007 Share Posted November 28, 2007 lol obviously... One out of many conversions that htmlentities() does is convert "<" to '<'. So obviously when you are searching for "<" in the string you won't find it. But htmlentities() doesn't convert a capital A to something special, so if $_POST['comment'] contained a capital A, $comment will contain that A too... Orio. Quote Link to comment Share on other sites More sharing options...
Taffd Posted November 28, 2007 Author Share Posted November 28, 2007 Many thanks orio, I'll have to have a look at htmlentities in the manual to find out what else I don't know about it. Your help has been invaluable Best Regards Taffd Quote Link to comment 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.