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);
}

:)

  • As I just tweeted to you - could you post the function where this is occurring. – madebyhippo Dec 6 '13 at 11:44
  • Will add to my original post. Thanks. :) – Nathan Pitman Dec 6 '13 at 11:51
  • There you go. It's 'footnoteRef' that's throwing the error. – Nathan Pitman Dec 6 '13 at 11:53
up vote 4 down vote accepted
+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);
}
  • Hoorah, this worked out the box. Thanks Richy. – Nathan Pitman Dec 6 '13 at 12:08

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.

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

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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