preg_replace() [function.preg-replace]:/home/中的未知修饰符“/" [英] preg_replace() [function.preg-replace]: Unknown modifier '/' in /home/

查看:45
本文介绍了preg_replace() [function.preg-replace]:/home/中的未知修饰符“/"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的网站中,我想用这样的其他链接替换链接

in my website i want to replace links with some other link like this

www.abc.comhttp://abc.com 将替换为

http://www.XXXXXX.com/sonal?www.abc.com

http://www.XXXXXX.com/sonal?http://abc.com

所以我正在使用这段代码,但这段代码出现了一些错误

so i am using this code but this code is giving some error

警告:preg_replace() [function.preg-replace]:未知修饰符'/'在/home/XXXXX/public_html/YYYYYYYYY/KKKKKK.php 第 495 行

$search_array = array(
   "/\[url]www|http://.([^'\"]*)\[\/url]/iU",
   "/\[url]([^'\"]*)\[\/url]/iU",
   "/\[url=www|http://.([^'\"\s]*)](.*)\[\/url]/iU",
   "/\[url=([^'\"\s]*)](.*)\[\/url]/iU"
);
$replace_array = array(
   "<a href=\"http://XXXXXX.com/sonal?.\\1\" target=\"_blank\" rel=\"nofollow\">www.   \\1</a>",
   "<a href=\"\\1\" target=\"_blank\" rel=\"nofollow\">\\1</a>",
   "<a href=\"http://XXXXXX.com/sonal?.\\1\" target=\"_blank\" rel=\"nofollow\">\\2</a>",
   "<a href=\"\\1\" target=\"_blank\" rel=\"nofollow\">\\2</a>"
);

$msg = preg_replace($search_array, $replace_array, $msg);
return $msg;

推荐答案

解决这个问题的方法很少

There is few ways to solve that

转义/"

$search_array = array(
  "/\[url]www|http:\/\/.([^'\"]*)\[\/url]/iU",
  "/\[url]([^'\"]*)\[\/url]/iU",
  "/\[url=www|http:\/\/.([^'\"\s]*)](.*)\[\/url]/iU",
  "/\[url=([^'\"\s]*)](.*)\[\/url]/iU"
);

或者使用不同的正则表达式分隔符,如#"

Or using different regexp seperator like "#"

$search_array = array(
  "#\[url]www|http://.([^'\"]*)\[\/url]#iU",
  "#\[url]([^'\"]*)\[\/url]#iU",
  "#\[url=www|http://.([^'\"\s]*)](.*)\[\/url]#iU",
  "#\[url=([^'\"\s]*)](.*)\[\/url]#iU"
);

这篇关于preg_replace() [function.preg-replace]:/home/中的未知修饰符“/"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆