3

I'm using the Textile plug-in on a new project and it's spawning PHP errors all over the place and complaining thusly:

A PHP Error was encountered Severity: 8192

Message: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead

Filename: textile/pi.textile.php

Line Number: 918

Not one I've run into before but this is occurring in my local dev env on a new MacBook so it's a fresh install of MAMP running PHP 5.5.3.

Any ideas???

Update: I only see the PHP error in the front end templates when logged in as Admin.

The function generating the error is 'footNoteRef':

function footnoteRef($text)
{
    return preg_replace('/(?<=\S)\[([0-9]+)\](\s)?/Ue',
        '$this->footnoteID(\'\1\',\'\2\')', $text);
}

:)

2
  • As I just tweeted to you - could you post the function where this is occurring. Dec 6 '13 at 11:44
  • There you go. It's 'footnoteRef' that's throwing the error. Dec 6 '13 at 11:53
6
+50

According to http://uk1.php.net/preg_replace , the /e modifier was removed in PHP 5.5.0 . If you downgrade PHP to pre-5.5.0, then the error will go away. Alternatively, in your config.php file set error_reporting(E_ALL ^ E_DEPRECATED); to hide deprecated warnings.

Alternatively, upgrade Textile - but it looks like http://devot-ee.com/add-ons/textile-editor-helper-teh hasn't been upgraded in some time.

=== Added after you posted the code ==

Try changing

function footnoteRef($text)
{
    return preg_replace('/(?<=\S)\[([0-9]+)\](\s)?/Ue',
        '$this->footnoteID(\'\1\',\'\2\')', $text);
}

to (untested)

function footnoteRef($text)
{
    return preg_replace_callback('/(?<=\S)\[([0-9]+)\](\s)?/U',
function ($matches) {
            return $this->footnoteID($matches[1],$matches[2]);
        },
         $text);
}
1
  • Hoorah, this worked out the box. Thanks Richy. Dec 6 '13 at 12:08
0

So, if you remove everything from the function as it is and replace it with the following:

preg_replace_callback('/(?<=\S)\[([0-9]+)\](\s)?/U',
                   create_function('$matches','return $this->footnoteID($matches[1],$matches[2])'), $text);

This is totally untested, but I think it's right. No doubt if it's not, someone will chime in - Regular Expressions are not my forte.

2
  • Didn't work for me, I got another PHP error but thanks anyway. Pretty sure it's just missing a character here or there. :) Dec 6 '13 at 12:09
  • Whats the error? Dec 6 '13 at 12:13
0

after upgrading to php 7.3 you will likely see a similar error related to textile compilation

preg_replace_callback(): Compilation failed: invalid range in character class at offset 184
user/addons/textile/pi.textile.php, line 628

this is explained quite well in this stackoverflow thread: https://stackoverflow.com/a/56551371/11512584

PHP PCRE engine migrates to PCRE2, and the PCRElibrary version used in PHP 7.3 is 10.32, and that is where Backward Incompatible Changes originate from

on line 615 column 38 of pi.textile.php there was an unescaped hyphen, adding a backslash before this hyphen was enough to resolve the compilation error in my case (expression engine 5.4.2, using Textile plugin for ExpressionEngine 2.x)

diff:

615c615
<       $qtags = array('\*\*','\*','\?\?','\-','__','_','%','\+','~','\^');
---
>       $qtags = array('\*\*','\*','\?\?','-','__','_','%','\+','~','\^');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.