Jump to content

Topic on Extension talk:Pdf Export

MW 1.26 PHP7 PrinceXML PdfExport 3.2.0 - ParseError / preg_replace

1
Lanthanis (talkcontribs)

Due to security issues the modifier /e of the method preg_replace is not supported in PHP7 anymore.

I use a Windows Server 2012 R2 with PrinceXML.

The error occures in the PrincePdfConverter.php and suggest to use the new method preg_replace_callback.

This is the old code:

// set upper limit for width
  $bhtml = preg_place('/width="(\d+)"/e', "width=\"".($1 > $wgPdfExportMaxImageWidth ? $wgPdfExportMaxImageWidth : $1). "\"", $bhtml);

I got a ParseError while changing the code to:

//set upper limit for width
  $bhtml = preg_replace_callback ('/width="\d+"/', 'replaceCallback', $bhtml);
      
  function replaceCallback() {
          
       return "width=\"".($1> $wgPdfExportMaxImageWidth ? $wgPdfExportMaxImageWidth : $1)."\"";
          
  }

The $wgPdfExportMaxImageWidth variable is a global one. Does anyone know a bit PHP and can help me ?

PHP Manual - preg_replace

PHP Manual - preg_replace_callback

Reply to "MW 1.26 PHP7 PrinceXML PdfExport 3.2.0 - ParseError / preg_replace"