This was my first attempt. It works, but allows for unequal spaces on either side of tagname. 0 on one side and 1 on the other will match:
Code:
'/^(<!\-\-)\s?' . $tagname . '\s?(\-\->)$/'
My second attempt will force the tagname to either be surrounded by one space or no spaces, but looks a bit sloppy. I think there is another way to write it, but I couldn't figure it out. Hopefully someone here knows how because I would like to know too.
Code:
'/^(<!\-\-)(' . $tagname . '| ' . $tagname . ' )(\-\->)$/'
PHP Code:
<?php
$tagname = 'tagname';
$correct = '<!-- tagname -->';
$pattern = '/^(<!\-\-)\s?' . $tagname . '\s?(\-\->)$/';
//$pattern = '/^(<!\-\-)(' . $tagname . '| ' . $tagname . ' )(\-\->)$/';
if (preg_match($pattern, $correct))
echo 'Matched';
else
echo 'Did not match';
exit;
Bookmarks