I have an html document with multiple commented-out PHP arrays, e.g.:
<!-- Array
(
[key] => 0
)
-->
Using PHP, I need to somehow parse the HTML for only these comments (there are other comments that will need to be ignored) and extract the contents. I’ve been trying to use preg_match_all but my regex skills aren’t up to much. Could anyone point me in the right direction?
Any help is much appreciated!
Three facts come into play here
<!--” can show up and not mean a comment (everywhere else it would be escaped as “&!--“)The above combination means that (lo and behold) regular expressions can be used to identify HTML comments.
Try this regex:
<!-- Array([\s\S])*?-->. Match group one will contain everything after"Array"up to the closing sequence of the comment.You can apply further sanity checking to the found bits to make sure they are in fact what you are looking for.