Forum


Replies: 3   Views: 3609
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  · 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);

        }