Php 需要更换不推荐的ereg_replace

Php 需要更换不推荐的ereg_replace,php,preg-replace,ereg-replace,Php,Preg Replace,Ereg Replace,我为一家非营利机构工作,我不是PHP方面的专家 我需要替换以下代码: $status = ereg_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]", "<a href=\"\\0\">\\0</a>", $status); $status=ereg_replace(“[[:alpha:][]+://[^[:space:][]+[:alnum://]”,“”,$status); 当我试图将其修改为pr

我为一家非营利机构工作,我不是PHP方面的专家

我需要替换以下代码:

$status = ereg_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]", "<a href=\"\\0\">\\0</a>", $status);
$status=ereg_replace(“[[:alpha:][]+://[^[:space:][]+[:alnum://]”,“”,$status);
当我试图将其修改为preg_replace时,每次尝试退出代码时都会出现错误

这将完成工作:

$statut = preg_replace('~[a-z]+://[^<>\s]+[\w/]~i', '<a href="$0">$0</a>', $statut);
$statut=preg_replace('~[a-z]+://[^\s]+[\w/]~i',''.$statut);

但是,如果此替换的目标是保留所有URL并将其转换为链接,则必须稍微更改模式。还有,为什么不呢,用filter\u validate\u url测试它们

别忘了regex分隔符。你能给我们一些关于“我得到一个错误”的详细信息吗。