zoukankan      html  css  js  c++  java
  • 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:xampplitehtdocs estwp-contentpluginswidget-testwidget-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

  • 相关阅读:
    Linux之apt-get无sudo权限安装软件
    Java stream 并发应用案例
    java 执行 shell脚本通过mysql load data导入数据
    修改mysql存储过程或函数的定义着
    [ERR] 1118
    定时杀死mysql中sleep的进程
    centos7安装配置MariaDB10
    Tomcat设置JVM参数
    通Shell获取Tomcat进程号并杀死进程
    对于之前已经push的项目增加.gitignore配置文件不起作用的处理
  • 原文地址:https://www.cnblogs.com/Renyi-Fan/p/9116443.html
Copyright © 2011-2022 走看看