PHP-Function ereg_replace() is deprecated
class autoActiveLink {
function makeA开发者_JAVA技巧ctiveLink($originalString){
$newString = ereg_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]","<a href=\"\\0\" target=\"_blank\">\\0</a>", $originalString);
return $newString;
}
}
What should I replace the function ereg_replace
with? I tried preg_replace
, but the error still persists.
Try
class autoActiveLink {
function makeActiveLink($originalString){
$newString = preg_replace('#([A-Za-z]+://[^<>\s]+[A-Za-z0-9/])#','<a href="$1" target="_blank">$1</a>', $originalString);
return $newString;
}
}
preg_replace()
http://php.net/manual/en/function.preg-replace.php
It is not reasonable that the error still exists after you replaced it to preg_replace
But the pattern syntax is different, youll have to convert it
精彩评论