Ewen Cumming schreef:
OK, problem solved. Using preg_last_error shows that the backtrack limit
gets exhausted, it can be fixed by increasing the pcre.backtrack_limit in
php.ini.
aha. I was aware of it, but I've never run into it myself.
Probably a better fix would be to improve the regex - I'll look into using
the one you suggested.
I'd be interested to know if it's an improvement. (how does one measure regexp
performance properly anyway?)
In terms of performance it's not a good idea to be doing this replacement
on every request, you might consider running the replacement in an out of
process job and saving the results (on the cmdline you can up the backtrace limit
without serious reprecussions)
maybe DOM or XML would be faster too (you may need to define a DTD for your 'tags' ...
not sure if your tags are even XML compliant):
http://php.net/manual/en/intro.dom.php
http://php.net/manual/en/intro.xml.php
http://php.net/manual/en/intro.xmlreader.php
Another thing to think about is tokenizing the string, and running through the string
one small piece at a time (rather than the complete template).
Alternatively split the string/template into a number of sections and run the
regexp on each ... obviously you'll have to have some logic that determines whether
the last item found in a previous section is actually an opening 'replacement tag'
with content and an ending 'replacement tag'.
Thanks again for your help,
Ewen
2008/9/12 Jochem Maas <jochem@xxxxxxxxxxxxx>
Ewen Cumming schreef:
Actually bummer - testing on wrong version.
The U modifier is causing problems too - only matching the first character
instead of the whole string.
hmm, missed that, that might require adding ?U to relevant sub-assertion
...
I'm wondering if your regexp is not 'wrong' (big word in this case),
try this variation:
$pattern = '#<\\!T_([^> ]+)([^>]*)>(?:(.*)?<\\!T_end\\1>)?#si';
gives me the same output as your expected results, albeit that there
are less 'root' keys in the matches array ... so you may need to
change some code with regard to fishing out values from $matches
2008/9/12 Ewen Cumming <ewen.cumming@xxxxxxxxx>
Hi Jochem,
Replacing the 's' modifier with 'm' fixed it this instance but broke
other
parts on the site (the same result as removing 's').
But the other regex ( $pattern = "/<!T_([^>
]+)([^>]*)>(.*?)<!T_end\\1>|<!T_([^>
]+)([^>]*)>/Ui";) is working perfectly.
I will continue to test and see if it throws up any other problems. Many
thanks for such a quick and great response.
I will file a bug report however I may need to submit the full test
string
as cutting it down any further seems to 'fix' the discrepency.
Thanks again,
Ewen
2008/9/12 Jochem Maas <jochem@xxxxxxxxxxxxx>
Jochem Maas schreef:
Ewen Cumming schreef:
Hi everybody,
...
BUT I may have work around for you, try this regexp (replaces s modifer
with m modifier):
$pattern = "/<!T_([^> ]+)([^>]*)>(.*?)<!T_end\\1>|<!T_([^>
]+)([^>]*)>/mi";
the following pattern also seems to do what you want:
$pattern = "/<!T_([^> ]+)([^>]*)>(.*?)<!T_end\\1>|<!T_([^>
]+)([^>]*)>/Ui";
Im interested to know if either of these two solve your immediate issue.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php