I have several HTML pages with codes that look like this:
<!-- ID: 123456 -->
What I need is a PHP script that can pull that ID number. I have tried the following:
if (preg_match('#^<!--(.*?)-->#i', $output)) {
echo "A match was found.";
} else {
echo array_flip(get_defined_constants(true)['pcre'])[preg_last_error()];
echo "No match found.";
}`
That always gives "No match found", with no error reported. I have also tried the preg_match_all and the same results. The only thing I have found to work is to create an array based on spaces, but that is very time consuming and waste of processor power.
For reference, I have looked and tried just about every suggestion on these pages:
Explode string by one or more spaces or tabs
http://php.net/manual/en/function.preg-split.php
How to extract html comments and all html contained by node?
-is a special symbol and should be escaped?^from the pattern. Otherwise, it will match only at the start of the string.$outputis the string with<!-- ID: 123456 -->or the ID you want captured? Works here, eval.in/437735. Might needmmodifier if you want the<!to be only at the start of each line.-is not a special symbol, except inside square brackets.