Since Php 5.4, the /e modifier in preg_replace function has been deprecated and thus the code which uses this modifier should be modified or it will stop working. How can you do that? Simple. Let’s look on the source code of mPDF. We have the following:
$html = preg_replace(‘/\{DATE\s+(.*?)\}/e’,”date(‘\\1’)”,$html );
What this does is replacing for example {DATE d-m-y} with the PHP function of date(‘d-m-y’). We should modify this line as we can see it uses the /e modifier and it won’t work anymore on php 5.5. To replace it, we use the preg_replace_callback function like this:
$html = preg_replace_callback(‘/\{DATE\s+(.*?)\}/’,create_function(‘$matches’, ‘return date($matches[1]);’),$html );
Or even better using PHP 5.5 standards:
$html = preg_replace_callback(‘/\{DATE\s+(.*?)\}/’, function($matches) { return date($matches[1]); },$html );
What this does is that it creates a anonymus function and returns the date() function with the matches.
So, the alternative method to the /e modifier is to use the preg_replace_callback function in Php 5.5 or 5.4.
Hello,
Thank you for sharing this. It works like a charm …