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. 【习题 7-6 UVA - 12113】Overlapping Squares

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 先预处理出来一个正方形. 然后每次枚举新加的正方形左上角的坐标就可以. 注意覆盖的规则,控制一下就可以. 然后暴力判断是否相同. 暴 ...

  2. Apache httpd.conf 配置文件语法验证

    Apache 的 httpd.conf文件改动之后,必须重新启动server才干生效. 有时server在提供服务的时候,直接更改配置,重新启动服务.会带来非常大的危急性. 假设能在改动配置之后,先验 ...

  3. LOJ 6229 LCM / GCD (杜教筛+Moebius)

    链接: https://loj.ac/problem/6229 题意: \[F(n)=\sum_{i=1}^n\sum_{j=1}^i\frac{\mathrm{lcm}(i,j)}{\mathrm{ ...

  4. StringBuilder类的使用总结

    String 对象是不可改变的.每次使用 System.String 类中的方法之一时,都要在内存中创建一个新的字符串对象,这就需要为该新对象分配新的空间.在需要对字符串执行重复修改的情况下,与创建新 ...

  5. mysql数据库忘记密码时如何修改(转)

    当我们忘记mysql数据库密码时我们就无法正常进入数据库,也就无法修改密码,那么这时该怎么修改密码呢,这里教大家一个简单常用修改密码的方式. (如果图简单快速修改密码的话,直接跳过查询步骤,依照图上执 ...

  6. select下拉列表选中后,跳转新链接

    1.在当前页面打开新链接 <select onchange="location.href=this.options[this.selectedIndex].value" na ...

  7. nodeJS+socket.io传递消息

    服务器端 安装express,socket.io npm install express --save-dev npm install socket.io --save app.js const ex ...

  8. Git 经常使用命令

    Git经常使用命令备忘: Git配置 git config --global user.name "storm" git config --global user.email &q ...

  9. 通过WMI的方式去设置LCD背光亮度

    code例如以下: #include "stdafx.h" #include <objbase.h> #include <windows.h> #inclu ...

  10. amazeui学习笔记--css(基本样式4)--打印样式Print

    amazeui学习笔记--css(基本样式3)--打印样式Print 一.总结 1.打印显示url方法: 利用 CSS3 content 属性,将 <a> 和 <abbr> 的 ...