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
Warning: preg_replace(): Compilation failed: missing terminating ] for character class at offset 10 in的更多相关文章
- 错误记录PHP preg_match(): Compilation failed: range out of order in character class at offset 7 01_login.php</b> on line <b>13</b><br />
<?php //响应头格式为json,编码为uft-8,注意有- header("Content-Type:application/json;charset=utf-8"); ...
- PHP Warning: preg_match(): JIT compilation failed: no more memory in
PHP7.3出现如下错误:PHP Warning: preg_match(): JIT compilation failed: no more memory in ... 解决方案: 修改 /usr/ ...
- idea报错:error java compilation failed internal java compiler error
idea下面报如下问题 error java compilation failed internal java compiler error 解决办法:Setting->Compiler-> ...
- jsmooth compilation failed error null
JSmooth 0.9.9-7 在将 jar 文件打包成 exe 文件时报错:jsmooth compilation failed error null 原因,没有指定 logo 图片文件. http ...
- idea Error:java: Compilation failed: internal java compiler error
idea 遇到Error:java: Compilation failed: internal java compiler error 是提示说你当前使用的编译器jdk版本不对. 按住Ctrl+Alt ...
- Error:java:Compilation failed: internal java compiler error
在IDEA中编译时出现这个错误:Error:java:Compilation failed: internal java compiler error! Information:Using javac ...
- Android resource compilation failed
报错:Android resource compilation failed D:\android\EasySports\app\build\intermediates\incremental\mer ...
- WARNING: 'aclocal-1.14' is missing on your system.
源码安装zabbix agent时进行到make install时报如下错误: WARNING: 'aclocal-1.14' is missing on your system. You shoul ...
- android -------- 混淆打包报错(warning - InnerClass annotations are missing corresponding EnclosingMember annotations)
最近做Android混淆打包遇到一些问题,Android Sdutio 3.1 版本打包的 错误如下: Android studio warning - InnerClass annotations ...
随机推荐
- WPF 入门《数据绑定》
简单而言, 数据绑定是一种关系, 这种关系告诉WPF 从一个源目标对象中提取一些信息, 并且使用该信息设置为目标对象的属性.目标属性总是依赖项属性, 并且通常位于WPF元素中. 然而, 源对象可以是任 ...
- onWindowFocusChanged-屏幕焦点函数回调情况
1.这个函数的具体作用不太清楚,但网上有人说是 ,当activity得到或者失去焦点的时候,就会调用这个方法 先看如下代码 @Override public void onWindowFocusCha ...
- vue权限控制菜单显示的简单实现
为了对于不同角色显示不同的菜单 思路1: 本地放一份完整的菜单数据,通过后台返回角色的菜单列表.两者对比,筛选需要显示的菜单数据绑定, 这里有个问题就是路由vue实例初始化就生成了,加载的全部,人为输 ...
- 00099_commons-IO
1.导入classpath (1)加入classpath的第三方jar包内的class文件才能在项目中使用: (2)创建lib文件夹: (3)将commons-io.jar拷贝到lib文件夹: (4) ...
- 细说GCD
http://blog.csdn.net/hsf_study/article/details/51637453
- comparator接口与Comparable接口的差别
1. Comparator 和 Comparable 同样的地方 他们都是java的一个接口, 而且是用来对自己定义的class比較大小的, 什么是自己定义class: 如 public class ...
- ping 本地端口
C:\Users\Administrator>netstat -ano | findstr 8001
- php实现变态跳台阶(记忆化递归)
php实现变态跳台阶(记忆化递归) 一.总结 1.本题思路(分类讨论思路,注意初始值和边界值):第一步如果1,那剩下的就是jumpFloorII($number-1)(下面jumpFloorII以j表 ...
- 基于PHP实现一个简单的在线聊天功能(轮询ajax )
基于PHP实现一个简单的在线聊天功能(轮询ajax ) 一.总结 1.用的轮询ajax 二.基于PHP实现一个简单的在线聊天功能 一直很想试着做一做这个有意思的功能,感觉复杂的不是数据交互和表结构,麻 ...
- 微信端 h5 视频 video 自动播放
document.addEventListener("WeixinJSBridgeReady",function(){ document.getElementById(" ...