Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/amazon-s3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 将特定的eregi_替换转换为preg_替换功能_Php_Regex - Fatal编程技术网

Php 将特定的eregi_替换转换为preg_替换功能

Php 将特定的eregi_替换转换为preg_替换功能,php,regex,Php,Regex,我知道这并不是一个新问题,但我不是preg_replace函数的专家。我曾经在互联网上发现过将URL等转换为可点击链接的代码,但由于PHP5.3,我收到了一个“弃用”通知,不知道如何修复它。。。我尝试添加/分隔符,但没有成功。有什么想法吗 function clickLinks($sText) { $sText = eregi_replace('(((f|ht){1}tp://)[-a-zA-Z0-9@:%_+.~#?&//=]+)', '<a href="\1" target

我知道这并不是一个新问题,但我不是preg_replace函数的专家。我曾经在互联网上发现过将URL等转换为可点击链接的代码,但由于PHP5.3,我收到了一个“弃用”通知,不知道如何修复它。。。我尝试添加/分隔符,但没有成功。有什么想法吗

function clickLinks($sText) {
 $sText = eregi_replace('(((f|ht){1}tp://)[-a-zA-Z0-9@:%_+.~#?&//=]+)',
 '<a href="\1" target="_blank"><font color="black">\1</font></a>', $sText);
 $sText = eregi_replace('([[:space:]()[{}])(www.[-a-zA-Z0-9@:%_+.~#?&//=]+)',
 '\1<a href="http://\2" target="_blank"><font color="black">\2</font></a>', $sText);
 $sText = eregi_replace('([_.0-9a-z-]+@([0-9a-z][0-9a-z-]+.)+[a-z]{2,3})',
 '<a href="mailto:\1"><font color="black">\1</font></a>', $sText);
return $sText;
}
功能点击链接($sText){
$sText=eregi_replace(“((f|ht){1}tp://)[-a-zA-Z0-9@:%+.~#?&/=]+),
“$sText);
$sText=eregi_replace(“([[:space:][{}])(www.[-a-zA-Z0-9@:%+.~#?&/=]+),
“\1”,$sText);
$sText=eregi_replace(“([[0-9a-z-]+@[0-9a-z][0-9a-z-]+])+[a-z]{2,3}”),
“$sText);
返回$sText;
}

但为了提供帮助。只需在模式的开头和结尾添加delimeters,我使用了#并用\转义模式中的任何分隔符,这样引擎就知道它不是delimeter,所以\:

$sText=preg#u replace('#((f|ht){1}tp://)[-a-zA-Z0-9@:%\+.~\\\#?&/=]+),
“$sText);

eregi和preg之间的主要区别是preg基于perl的regex,unix的eregi regex和preg_*函数必须以delemiter开头,如“/”

$regex  = '/[a-z]/'; 
preg_replace($regex, $replacement, $string)

有无数的例子。刚刚注意到char类中的/=,why two/?不知道为什么,只是从web上复制了代码,它完成了任务…非常感谢你的帮助!相应地更改了其余的代码,它又完美地工作了!嗯,
(f|ht){1}tp
相当紧张,我想
(ftp | http)
再清楚一点吗?
$regex  = '/[a-z]/'; 
preg_replace($regex, $replacement, $string)