Deprecated Function Help

I know that ereg_replace () needs to be updated to preg_replace() but I am not sure of how to rewrite the rest of the string. I am not familiar with PHP. Please let me know how to update this or of any resources I can use as a guide.

[php] function hyperlink(&$string){
// match protocol://address/path/
$string = ereg_replace("[a-zA-Z]+://([-][.]?[a-zA-Z0-9_/-?&%])", “<a target=“blank" href="\0">\0", $string);
// match www.something
$string = ereg_replace("(^| )(www([-]*[.]?[a-zA-Z0-9
/-?&%]))", “\1<a target=”_blank" href=“http://\2”>\2", $string);
//matches email
$string = ereg_replace(’[-a-z0-9!#$%&’
+/=?^`{|}~]+@([.]?[a-zA-Z0-9/-])*’,”<a href=“mailto:\0”>\0” ,$string);
return $string;
}[/php]

I just did a Google search on how to put a string into an anchor tag and came up with this

[php]<?php
function hyperlink($text) {
return preg_replace(’@(http)?(s)?(://)?(([-\w]+.)+([^\s]+)+[^,.\s])@’, ‘$1$2$3$4’, $text);
}

$string = ‘http://www.google.com’;

$link = hyperlink($string);

echo $link . “
”;

$string = ‘[email protected]’;

$link2 = hyperlink($string);

echo $link . “
”;
[/php]

Looking it over this won’t do what you exactly want it to do, but if you do another internet search I’m sure you could find a script that will. Or if someone who is really good with RegEx here might be able to help you out better than I can.

Thanks, Strider64. That fixed the deprecated function and I no longer get an error but now it looks like it broke relative and mailto links throughout the rest of the page.

Sponsor our Newsletter | Privacy Policy | Terms of Service