dongziche8030 2017-04-11 07:34
浏览 19
已采纳

preg_replace()[function.preg-replace]:编译失败:偏移量为8的不匹配括号

Why we are getting above error. When we run below code inside a for loop which is running more than 500.

$text22 = preg_replace('/\S*\b('. $searchphrase[$rr] .')\b\S*/i', '<b><a href='.$bbb.' data-color='.$colors1[$clx].','.$colors2[$clx].','.$colors3[$clx].'>$1</a></b>', $aaa);
  • 写回答

1条回答 默认 最新

  • douren2395 2017-04-11 15:04
    关注

    It's likely that the dynamic string you are placing into your regex contains characters that are special to regular expressions. An open parenthesis in the string would cause the "unmatched parentheses" error, and "at offset 8" is the second hint the issue is here. You should wrap regex variables in preg_quote:

    '/\S*\b('. preg_quote($searchphrase[$rr]) .')\b\S*/i'
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 MATLAB联合adams仿真卡死如何解决(代码模型无问题)
  • ¥15 基于pso参数优化的LightGBM分类模型
  • ¥15 安装Paddleocr时报错无法解决
  • ¥15 python中transformers可以正常下载,但是没有办法使用pipeline
  • ¥50 分布式追踪trace异常问题
  • ¥15 人在外地出差,速帮一点点
  • ¥15 如何使用canvas在图片上进行如下的标注,以下代码不起作用,如何修改
  • ¥15 Windows 系统cmd后提示“加载用户设置时遇到错误”
  • ¥50 vue router 动态路由问题
  • ¥15 关于#.net#的问题:End Function