Jump to content

Matching HTML-Comments using PCRE


Goldeneye

Recommended Posts

The following function attempts to match "<!--$tag-->

[html-MARKUP]<!--$tag-->" in $this->page.

$this->page is a string that contains HTML-Markup from an HTML-Template file.
$tag would be something like "repeat.content"

But right now it isn't matching despite there being a <!--repeat.content-->*<!--/repeat.content--> in $this->page, it still echo's "Template-Looping error!"

This leads me to believe that my regular-expression is wrong. So, my question -- is there anything wrong with my regular-expression?

<?php
function repeat($tag, $replacements){
if(preg_match_all('/\<\!\-\-'.$tag.'\-\-\>(.*?)\<\!\-\-\/'.$tag.'\-\-\>/i', preg_quote($this->page, '/'), $match)){
	$str = str_replace('<!--'.array_keys($replacements).'-->', array_values($replacements), $match[0]);
	echo $str;
} else
	echo '<p>Template-Looping error!</p>';
}
?>

Link to comment
https://forums.phpfreaks.com/topic/182862-matching-html-comments-using-pcre/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.