开发者

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜