Jump to content

Deprecated help for a newbie


bjenn85

Recommended Posts


function format_bbcode( $text )
  {
  $search  = array( '#\[url=(http|https|ftp)://(.+?)\](.+?)\[/url\]#ie', '#\[url\](http|https|ftp)://(.+?)\[/url\]#ie' );
  $replace = array( 'trunc_url(\'\\1://\\2\',\'\\3\')', 'trunc_url(\'\\1://\\2\',\'\\1://\\2\')' );
  return preg_replace( $search, $replace, $text );
  }
function make_urls( $text )
  {
  $search  = array( '#(^|\s)(http|https|ftp)(://[^\s\[]+)#i' );
  $replace = array( '\\1[url]\\2\\3[/url]' );
  return preg_replace( $search, $replace, $text );
  }

old tiny forum I use and since the latest PHP upgrade I've been building up a huge error_log for deprecated preg_replace

 

can someone please show me how to use preg_replace_callback on these two?

Link to comment
Share on other sites

Try changing the format_bbcode function to be

function format_bbcode( $text )
{
    $search  = array( 
        '#\[url=(http|https|ftp)://(.+?)\](.+?)\[/url\]#i', 
        '#\[url\](http|https|ftp)://(.+?)\[/url\]#i'
    );
    
    $text = preg_replace_callback($search, function($m) {
                                                $url = $m[1] . '://' . $m[2];
                                                $link_text = isset($m[3]) ? $m[3] : $url;
                                                return trunc_url($url, $link_text);
                                           }
                                        , $text);

    return $text;
}
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.