I am using the preg_replace function in PHP and am trying to replace urls that users submit with bit.ly shortened links:
$comment = preg_replace( '/(http|ftp)+(s)?:(\/\/)((\w|\.)+)(\/)?(\S+)?/i', '', $strText );
This will show only the comment and "wipe out" the url. The question is how can I get the URL from the text and append it later?
preg_replace_callback()
Example from php.net:
define a callback function that replaces the URL. It will receive the matches as a parameter, and inside you will form, depending on those matches, a replacement string.