So I have a very large _global_vars array (3205 items). Probably too large, but it is what it is and I can’t change it. I’m getting a “regular expression is too large” error b/c the $regex value in this loop is a very, very long string.
$regex = $this->getGlobalsRegex(); while (preg_match_all($regex, $this->template, $result))
I did some testing with a smaller _global_vars array (~600 items) by changing that loop to just do a strpos() on the template before swaping the variable contents. In my tests it took approximately 0.014 seconds to loop over the _global_vars array. The preg_match_all by comparison took approximately 0.005 seconds. Its about a 64% difference in speed, but still a very small fraction of time. Since preg_match_all has a limitation depending on the compiled php settings would it make sense to change it to a loop with a strpos check?
con: puts a limit on the number of _global_vars you can have
foreach & strpos
pro: no limit on the _global_vars