Reputation: 559
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 solution. Please, can you help me?
This is what I need:
<!--adress-"String here I need to get"-->
Thanks in advance for answer
Upvotes: 2
Views: 1217
Reputation: 222
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.
Upvotes: 1
Reputation: 887245
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.
Upvotes: 1
Reputation: 50966
Look into $matches after this code
preg_match('~<!--adress-"(.*?)"-->~msi', $string, $matches);
Upvotes: 4