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 Link to comment https://forums.phpfreaks.com/topic/79239-solved-simple-regex-problem/ 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. Link to comment https://forums.phpfreaks.com/topic/79239-solved-simple-regex-problem/#findComment-401092 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. Link to comment https://forums.phpfreaks.com/topic/79239-solved-simple-regex-problem/#findComment-401105 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. Link to comment https://forums.phpfreaks.com/topic/79239-solved-simple-regex-problem/#findComment-401109 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 Link to comment https://forums.phpfreaks.com/topic/79239-solved-simple-regex-problem/#findComment-401272 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.