Warning: preg_replace(): Compilation failed: missing terminating ] for character class at offset 10 in
Warning: preg_replace(): Compilation failed: missing terminating ] for character class at offset 10 in
一、总结
1、[是正则中特殊字符,需要用\反斜杠转义
二、Warning: preg_replace(): Compilation failed: missing terminating ] for character class at offset 10 in
1、问题
I've got a series of .txt files that I'm reading in a for loop. And I've placed a token in some of the text files in the form [widget_]
So, the entire contents of the text file might be [widget_search] for example. And another text file might contain the content [widget_recent-posts]. Others might just have html formatted text and not have the token at all.
In the for loop, I'm doing a preg_match to see if the text file is one in which the contents matches my token pattern. And if a match, I'm executing some conditional code.
However, I'm getting an error when I run a trace test to see if there's a match.
The error is:
Warning: preg_match() [function.preg-match]: Compilation failed: missing terminating ] for character class at offset 8 in C:\xampplite\htdocs\test\wp-content\plugins\widget-test\widget-test.php on line 227
And here's the code at line 227:
if (preg_match("/[widget_/i",$widget_text)) {//do something}
2、解答
You should escape the [ character like this:
if (preg_match("/\[widget_/i",$widget_text)) {//do something}
3、相似错误
$start="/^<![CDATA[/";
$v=preg_replace($start,"",$v);
三、测试题-简答题
1、正则中常见的需要转义的特殊字符?
解答:\. \/ \[ \( \( \d
最新文章
- C++_系列自学课程_第_11_课_类型转换_《C++ Primer 第四版》
- iOS开发~CocoaPods使用详细说明
- 简单区分VMware的三种网络连接模式(bridged、NAT、host-only)
- cdoj 1328 卿学姐与诡异村庄 Label:并查集 || 二分图染色
- atitit.无线网卡 不能搜索到WiFi 无线路由信号的解决不能上网
- 关于Fragment 不响应onActivityResult的情况分析 (
- python操作sqlite数据库
- 有关loading share object file libjvm.so: xxxxx 的那些问题
- 重构5-Pull Up Field(字段上移)
- We Recommend a Singular Value Decomposition
- 50道经典的JAVA编程题 (1-5)
- Can you find it?(二分 二分+STL set map)
- jquery 中时间的运用
- VirtualBox的共享文件夹功能的使用演示
- WPF Tutorial - Using A Visual Collection
- bzoj4271: chemistry 化学
- vue基础——事件处理
- 集合(三)CopyOnWriteArrayList
- LoadRunner如何监控Linux系统资源
- 24.Java中atomic包中的原子操作类总结
热门文章
- Vue 打包后报错 Uncaught TypeError: Cannot redefine property: $router
- Office2010激活工具
- echarts如何设置背景图的颜色
- STL中erase()的陷阱
- SFC梯形图编程
- Spring.net的Demo项目,了解什么是控制反转
- [Javascript AST] 1. Continue: Write a simple Babel plugin
- Windows环境下ARM集成开发环境的搭建与使用
- [bzoj1269]文本编辑器editor [bzoj1500]维修数列
- 文字记录而已!!人民币直充/兑换PayPal美金