我正在制作一个内容管理系统,打开以下代码时,我不断收到相同的错误(使用XAMPP):
解析错误:语法错误,第47行的C:\ xampp \ htdocs \ cms \ classes \ Article.php中出现意外的'@',期望的是')'
我已经尝试替换'@'whith')',但是仍然无法正常工作。如果这样做,错误将变为:
解析错误:语法错误,第47行的C:\ xampp \ htdocs \ cms \ classes \ Article.php中出现意外的':'
public function __construct( $data=array() ) {
if ( isset( $data['id'] ) ) $this->id = (int) $data['id'];
if ( isset( $data['publicationDate'] ) ) $this->publicationDate = (int) $data['publicationDate'];
if ( isset( $data['title'] ) ) $this->title = preg_replace ( "/[^.,-_'"@?!:$ a-zA-Z0-9()]/", "", $data['title'] );
if ( isset( $data['summary'] ) ) $this->summary = preg_replace ( "/[^.,-_'"@?!:$ a-zA-Z0-9()]/", "", $data['summary'] );
if ( isset( $data['content'] ) ) $this->content = $data['content'];
}
我希望它能正常运行。
答案 0 :(得分:0)
您应该转义这样的双引号:\“,只需在前面加上斜杠即可。
第7和8行的问题。 这段代码对我有用。
public function __construct( $data=array() ) {
if ( isset( $data['id'] ) ) $this->id = (int) $data['id'];
if ( isset( $data['publicationDate'] ) ) $this->publicationDate = (int) $data['publicationDate'];
if ( isset( $data['title'] ) ) $this->title = preg_replace ( "/[^.,-_'\"@?!:$ a-zA-Z0-9()]/", "", $data['title'] );
if ( isset( $data['summary'] ) ) $this->summary = preg_replace ( "/[^.,-_'\"@?!:$ a-zA-Z0-9()]/", "", $data['summary'] );
if ( isset( $data['content'] ) ) $this->content = $data['content'];
}