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 ...
随机推荐
- CISP/CISA 每日一题 15
CISA 每日一题(答) 作业记帐: 监控和记录信息系统资源的使用,这些信息可被信息系统审计师用来执行: 1.将资源使用和相关用户挂钩以便实行计费: 2.通过改变系统软件的默认设置来最优化硬件性能 作 ...
- UML学习之初步总结
UML(Unified Modeling Language)即统一建模语言,是一种开放的方法,用于说明.可视化.构建和编写一个正在开发的.面向对象的.软件密集系统的制品的开放方法.UML展现了一系列最 ...
- c++ 常识
1) 功能:格式化字符串输出 说明:format指定输出格式,后面跟要输出的变量 目前printf支持以下格式: %c 单个字符 ...
- AIX上安装Oracle10G软件
安装准备 (1)确认系统版本号.内核版本号 # oslevel –r //查看操作系统版本号 //-08能够安装10g,-09能够安装11g watermark/2/text/aHR0cDovL2 ...
- git stash备份当前工作区内容,回到最近一次commit提交
git stash: 备份当前的工作区的内容,从最近的一次提交中读取相关内容,让工作区保证和上次提交的内容一致.同时,将当前的工作区内容保存到Git栈中.git stash pop: 从Git栈中读取 ...
- python3 turtle 画围棋棋盘
python3 环境 利用turtle模块画出 围棋棋盘 #!/usr/bin/env python # -*- coding:utf-8 -*- # Author:Hiuhung Wan impor ...
- springboot 使用FreeMarker模板(转)
在spring boot中使用FreeMarker模板非常简单方便,只需要简单几步就行: 1.引入依赖: <dependency> <groupId>org.springfra ...
- php实现运气模型(命运随机,克服困难)
php实现运气模型(命运随机,克服困难) 一.总结 1.应该用表格来布局的,这种多列的用表格布局比div和span布局方便很多 2.span标签设置宽度:变成行内快元素:display:inline- ...
- python opencv3 —— 常用工具、辅助函数、绘图函数(图像添加文本、矩形等几何形状)
1. cv2.hconcat().cv2.vconcat() 将从摄像头捕获的多个图像帧,横向(cv2.hconcat)或纵向(cv2.vconcat)拼接到一起,使得可以在一个 window 中进行 ...
- jtag引脚
如果不能下载,可能原因也许是电量不足了... 在电力不足的时候,仿真也不能进行... ///////////////////////////////////////////////////////// ...