php pregmatch - ошибка компиляции - PullRequest
0 голосов
/ 28 января 2012

было интересно, может ли кто-нибудь помочь с этим. Я впервые вижу эту ошибку.

Предупреждение : 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]);
        }

Ответы [ 2 ]

1 голос
/ 28 января 2012

сообщение длиной от 3 до 500 символов

с регулярным выражением #^.{3,500}$#is все будет в порядке.

1 голос
/ 28 января 2012

То же, что и здесь, я думаю - вы не можете использовать * {} вместе:

Предупреждение: preg_match () [function.preg-match]: Ошибка компиляции: ничего не повторяется со смещением

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