I need to get string from comment in HTML file, I was trying to do it with DOM, but I didn't find good solution with this method.
So I want to try it with regular expressions, but I can't find satisfactory solutio开发者_如何学运维n. Please, can you help me?
This is what I need:
<!--adress-"String here I need to get"-->
Thanks in advance for answer
Look into $matches after this code
preg_match('~<!--adress-"(.*?)"-->~msi', $string, $matches);
HTML comments are regular; you can just match <!--adress-"([^">]+)"-->
and get the first group.
This assumes that the comments are always well-formed and always have a quoted string containing no quotes.
It will be more accurate:
$regex = '<!--(.+?)-"{0,1}(.+?)"{0,1}-->';
preg_match_all($regex, $html, $matches_array);
Just do the var_dump($matches_array)
and see results.
精彩评论