Forum


Replies: 3   Views: 3583
Unescaped regex
Topic closed:
Please note this is an old forum thread. Information in this post may be out-to-date and/or erroneous.
Every phpdocx version includes new features and improvements. Previously unsupported features may have been added to newer releases, or past issues may have been corrected.
We encourage you to download the current phpdocx version and check the Documentation available.

Posted by metricbpo  · 11-10-2013 - 22:09

Warning:  preg_replace(): Unknown modifier '/' in /usr/local/src/phpdocx_trial/classes/AutoLoader.inc(29) : eval()'d code on line 58

Stack trace:

  1. {main}() /domain/dev.ddesk/skiprm/edit.php:0

  2. preg_replace("/\$NOTE_DATE_d/m/Y\$/", "24/09/2013", "<?xml versio...



As $ is already escape, there are other possible variable characters that need escaping. The variable name contains / as NOTE_DATE_(.*) is being pumped into date() dynamically.


Posted by jorgelj  · 14-10-2013 - 09:21

Hello,



You need to escape '/' in PHPDocX code but you can use anyother symbol like '-'.



Regards.


Posted by metricbpo  · 14-10-2013 - 18:41

Our customers wish to use the / character in their templates. I also can't pass an escaped \/ to addTemplateVariable. It would seem more logical to escape the regex correctly within the PHPDOCX code like so:



        function regexEscape($regex)



        {

                $patterns = array('/', '^', '.', '$', '|', '(', ')', '[', ']', '*', '+', '?', '{', '}', ',');

                $replace = array('\/', '\^', '\.', '\$', '\|', '\(', '\)', '\[', '\]', '\*', '\+', '\?', '\{', '\}', '\,');

                return str_replace($patterns, $replace, $regex);

        }