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. 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.