【问题标题】:php pregmatch - Compilation failedphp preg_match - 编译失败
【发布时间】:2012-01-28 06:17:22
【问题描述】:

想知道是否有人可以帮助解决这个问题。这是我第一次看到这个错误。

警告:preg_match() [function.preg-match]:编译 失败:在偏移量 9 处没有可重复的内容

这与我的这部分代码无关:

( isset( $_POST[$post_key] ) && $misc[2] === true && ! preg_match( $misc[0], $_POST[$post_key] ) ) 

下面是我的完整(有点相关)代码。

发送过来的数据如下:

ajax-request    true
author          1
epi             2
jbid            781711001327010590
message         dfdf
type            send-invite

有人知道这是什么原因或导致错误的原因吗?

case 'send-invite' :

    if( free_member_is_logged_in() ) {

        $post_array = array(
            'message' => array(
                '#^.*{3,500}$#is',
                '<p class="error_message">Please enter a message between 3 and 500 characters.</p>',
                true
            ),
            'epi' => array(
                '#^[0-9]+$#is',
                '<p class="error_message">An internal error has occured. If this problem persists please contact support</p>',
                true
            ),
            'author' => array(
                '#^[0-9]+$#is',
                '<p class="error_message">An internal error has occured. If this problem persists please contact support.</p>',
                true
            ),
            'jbid' => array(
                '#^[0-9]+$#is',
                '<p class="error_message">Please specify a job which you have published.</p>',
                true
            )
        );

        $continue = true;

        foreach( $post_array as $post_key => $misc ) {
            if( 
                    ( ! isset( $_POST[$post_key] ) && $misc[2] === true ) 
                || 
                    ( isset( $_POST[$post_key] ) && $misc[2] === true && ! preg_match( $misc[0], $_POST[$post_key] ) ) 
                || 
                    ( isset( $_POST[$post_key] ) && $misc[2] === false && $_POST[$post_key] != '' && ! preg_match( $misc[0], $_POST[$post_key] ) ) 
            ) {

                $continue = false;
                $error_message = $misc[1];

            }
            ${cleankey($post_key)} = res($_POST[$post_key]);
        }

【问题讨论】:

    标签: php preg-match


    【解决方案1】:

    我猜和这里一样 - 你不能一起使用 *{}:

    Warning: preg_match() [function.preg-match]: Compilation failed: nothing to repeat at offset

    $post_array = array(
            'message' => array(
                '#^.*{3,500}$#is',
    

    【讨论】:

      【解决方案2】:

      3 到 500 个字符之间的消息

      正则表达式 #^.{3,500}$#is 就可以了。

      【讨论】:

      • 感谢您的帮助,抱歉没有刷新页面,所以下面的答案让我得出您的结论。无论如何干杯
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-15
      相关资源
      最近更新 更多