Jump to content

How to replace ereg function for PHP 7?


Styger

Recommended Posts

My web host recommend an upgrade to PHP 7 but my Wordpress theme is using a deprecated ereg expression that is breaking the comments section. Here's the offending code:

function the_commenter_link() {
    $commenter = get_comment_author_link();
    if ( ereg( ']* class=[^>]+>', $commenter ) ) {$commenter = ereg_replace( '(]* class=[\'"]?)', '\\1url ' , $commenter );
    } else { $commenter = ereg_replace( '(<a )/', '\\1class="url "' , $commenter );}
    echo $commenter ;
}

Reading posts online it seems that ereg needs to be replaced with preg_match and preg_replace. Is it a straight swap like written below or is there more to it than that?

function the_commenter_link() {
    $commenter = get_comment_author_link();
    if ( preg_match( ']* class=[^>]+>', $commenter ) ) {$commenter = preg_replace( '(]* class=[\'"]?)', '\\1url ' , $commenter );
    } else { $commenter = preg_replace( '(<a )/', '\\1class="url "' , $commenter );}
    echo $commenter ;
}

Thanks for your help!

Link to comment
Share on other sites

It's a woo theme that was retired in 2015 so there are no more updates. Everything seemed to work okay with PHP 7 except the comments section. I ran a search through the theme's PHP files and this was the only reference to ereg.

Thanks for the link but I still don't understand the proper syntax because I don't work with code. 

Edited by Styger
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.