Php 是否可能在preg_replace中进行URL编码?

Php 是否可能在preg_replace中进行URL编码?,php,preg-replace,urlencode,urldecode,preg-replace-callback,Php,Preg Replace,Urlencode,Urldecode,Preg Replace Callback,使用以下代码将文本中的URL转换为真正的HTML链接: $string = preg_replace("!(http|https|ftp|ftps)://([.]?[&;%#:=a-zA-Z0-9_/?-])*!", "<a href=\"away?to=\\0\">\\0</a>", $string); $string = preg_replace("!(^| |\n)(www([.]?[&;%#:=a-zA-Z0-9_/?-])+)!"

使用以下代码将文本中的URL转换为真正的HTML链接:

    $string = preg_replace("!(http|https|ftp|ftps)://([.]?[&;%#:=a-zA-Z0-9_/?-])*!", "<a href=\"away?to=\\0\">\\0</a>", $string);
    $string = preg_replace("!(^| |\n)(www([.]?[&;%#:=a-zA-Z0-9_/?-])+)!", "\\1<a href=\"away?to=www.\\2\">\\2</a>", $string);   
$string=preg_replace(“!(http | https | ftp | ftps):/([.]?[&;%]:=a-zA-Z0-9/?-)*!”,“,”,$string);
$string=preg_replace(“!(^ | | |\n)(www([.]?[&;%.:=a-zA-Z0-9/?-)+)!”,“\\1”,$string);
现在,包含#符号(可能还有其他特殊字符)的URL有问题,我需要
urlencode()
函数在这个
preg\u replace()函数中的某种方式


有什么想法吗

看看
preg\u replace\u callback
@Daan:你有关于我的代码的例子吗?从未使用过preg_replace_回调,也不了解我读到的关于如何在代码中使用它的内容。您想将
urlencode()
函数放置在哪里?@RahilWazir在
away?to=