douwen0612 2014-06-02 02:52
浏览 70
已采纳

错误“语法错误,意外'preg_match'(T_STRING)在”

I keep getting this error message saying:

syntax error, unexpected 'preg_match' (T_STRING) in

In this line:

Public function isDataValid()
{
return (preg_match('/^[a-zA-Z0-9](5-12)$/',$this->_username) (preg_match('/^[a-zA-Z0-9](8-12)$/',$this->_password)))? 1 = 0;

Can't figure this out. Help

  • 写回答

1条回答 默认 最新

  • doujiao8491 2014-06-02 02:55
    关注

    The error is about second preg_match because you have missing && OR || between those conditions. And also wrong = must be : if you use one line statement of if like below.

    (condition) ? "here_what_if_the_condition_is_true" : "and_here_if_it_is_wrong" ;
    

    look:

    return (preg_match('/^[a-zA-Z0-9](5-12)$/',$this->_username) (preg_match('/^[a-zA-Z0-9](8-12)$/',$this->_password)))? 1 = 0;
    

    And correct one is:

    return (preg_match('/^[a-zA-Z0-9](5-12)$/',$this->_username) && (preg_match('/^[a-zA-Z0-9](8-12)$/',$this->_password))) ? 1 : 0;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?