Forum Moderators: coopster
Problem is, some of the variables may involve quite a bit of work to get the right value; and I don't want the server to get tied up running functions that aren't going to get used.
So, my thinking is to do a
str_replace("<!--companyname-->", function_to_get_name, $output); only if <!--companyname--> is there. What I'd like to do is to load all of the comments into an array, so that I can just do "if in_array();" then do the replacement. Problem is, I can't figure out how to parse all the comments into an array.
How's that for a long, drawn out question? :-)
So...
$mystring = "yada, yado <!--tagnumber1--> some more stuff <!--anothercode--> and some more";
$return = preg_match("/^(<!--)?(-->)/i", $mystring, $matches);
Would make...
$matches[0] = "tagnumber1";
$matches[1] = "anothercode";
Look about right?
1. The $matches[0] contains the full string matched, so your results should start with $mathces[1] -- do a print_r($matches)
2. You need to make your pattern ungreedy and caputre the contents of the comment in parentheses, not the comment delimiters themselves
$pattern = '/^<!--(.*)-->/iU';