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的更多相关文章

  1. 错误记录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"); ...

  2. 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/ ...

  3. idea报错:error java compilation failed internal java compiler error

    idea下面报如下问题 error java compilation failed internal java compiler error 解决办法:Setting->Compiler-> ...

  4. jsmooth compilation failed error null

    JSmooth 0.9.9-7 在将 jar 文件打包成 exe 文件时报错:jsmooth compilation failed error null 原因,没有指定 logo 图片文件. http ...

  5. idea Error:java: Compilation failed: internal java compiler error

    idea 遇到Error:java: Compilation failed: internal java compiler error 是提示说你当前使用的编译器jdk版本不对. 按住Ctrl+Alt ...

  6. Error:java:Compilation failed: internal java compiler error

    在IDEA中编译时出现这个错误:Error:java:Compilation failed: internal java compiler error! Information:Using javac ...

  7. Android resource compilation failed

    报错:Android resource compilation failed D:\android\EasySports\app\build\intermediates\incremental\mer ...

  8. WARNING: 'aclocal-1.14' is missing on your system.

    源码安装zabbix agent时进行到make install时报如下错误: WARNING: 'aclocal-1.14' is missing on your system. You shoul ...

  9. android -------- 混淆打包报错(warning - InnerClass annotations are missing corresponding EnclosingMember annotations)

    最近做Android混淆打包遇到一些问题,Android Sdutio 3.1 版本打包的 错误如下: Android studio warning - InnerClass annotations ...

随机推荐

  1. WPF 入门《数据绑定》

    简单而言, 数据绑定是一种关系, 这种关系告诉WPF 从一个源目标对象中提取一些信息, 并且使用该信息设置为目标对象的属性.目标属性总是依赖项属性, 并且通常位于WPF元素中. 然而, 源对象可以是任 ...

  2. BZOJ 3732 Network Kruskal+倍增LCA

    题目大意:给定一个n个点m条边的无向连通图.k次询问两点之间全部路径中最长边的最小值 NOIP2013 货车运输.差点儿就是原题...仅仅只是最小边最大改成了最大边最小.. . 首先看到最大值最小第一 ...

  3. 5.decltype类型拷贝

    #include <iostream> using namespace std; template <class T> void show(T *p) { //初始化 decl ...

  4. 1.2 Use Cases中 Event Sourcing官网剖析(博主推荐)

    不多说,直接上干货! 一切来源于官网 http://kafka.apache.org/documentation/ Event Sourcing 事件采集 Event sourcing is a st ...

  5. FreeMarker template error: The following has evaluated to null or missing

    使用freemarker前端分页,报错: FreeMarker template error: The following has evaluated to null or missing 后端直接赋 ...

  6. 笔记三:JS正则表达式

    正则表达式(英语:Regular Expression,在代码中常简写为regex.regexp或RE)使用单个字符串来描述.匹配一系列符合某个句法规则的字符串搜索模式.说白了正则表达式就是处理字符串 ...

  7. 洛谷—— P1118 [USACO06FEB]数字三角形Backward Digit Su…

    https://www.luogu.org/problem/show?pid=1118#sub 题目描述 FJ and his cows enjoy playing a mental game. Th ...

  8. poj 1191 棋盘切割 (压缩dp+记忆化搜索)

    一,题意: 中文题 二.分析: 主要利用压缩dp与记忆化搜索思想 三,代码: #include <iostream> #include <stdio.h> #include & ...

  9. Android 监听软键盘点击回车及换行事件

    mEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean ...

  10. Docker---(2)docker pull 下来的镜像存储在哪里

    原文:Docker---(2)docker pull 下来的镜像存储在哪里 版权声明:欢迎转载,请标明出处,如有问题,欢迎指正!谢谢!微信:w1186355422 https://blog.csdn. ...