bjenn85 Posted August 30, 2015 Share Posted August 30, 2015 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? Quote Link to comment https://forums.phpfreaks.com/topic/297989-deprecated-help-for-a-newbie/ Share on other sites More sharing options...
Ch0cu3r Posted August 30, 2015 Share Posted August 30, 2015 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; } Quote Link to comment https://forums.phpfreaks.com/topic/297989-deprecated-help-for-a-newbie/#findComment-1519945 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.