Perad Posted December 9, 2009 Share Posted December 9, 2009 Can someone help please. This matches a well constructed comment. echo preg_match("<!--(.*?)-->", $value); How do I find a '<!--' that is missing a '-->'? Quote Link to comment Share on other sites More sharing options...
JAY6390 Posted December 9, 2009 Share Posted December 9, 2009 at a guess use this '/(<!--[^>]+<)/s' Quote Link to comment Share on other sites More sharing options...
cags Posted December 9, 2009 Share Posted December 9, 2009 Just a minor note to the OP, the pattern you posted probably doesn't match what you think it does. I doubt you'll run into any situation where it'll make much difference, but it's better to have it correct. All preg_ patterns must have delimiters generally speaking this is the same non-alphanumeric character before and after the pattern, but there are exceptions to this and bracket style character 'pairs' can be used. For this reason your pattern is not actually matching the < at the start and the > at the end. It is instead using them as the delimiters. To see what I mean (if you can't from my description) run this string though your current pattern... This is an example !--this isn't a comment-- it's part of my text. You should consider adding delimiters to the pattern. '#<!--(.*?)-->#' Quote Link to comment Share on other sites More sharing options...
Brandon_R Posted December 9, 2009 Share Posted December 9, 2009 How do I find a '<!--' that is missing a '-->'? if (!preg_match('#(?><!--.*?(?=<!--|-->|$))(?!-->)#si', $html)) { echo 'Your HTML tag is valid because it contains both opening and closing comment tags'; } else { echo 'Your HTML tag is invalid because it doesn't contain a closing tag --> for the opening <!-- comment tag'; } 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.