-1

I am making a Content Management System, and when opening the following code I keep getting the same error (using XAMPP):

Parse error: syntax error, unexpected '@', expecting ')' in C:\xampp\htdocs\cms\classes\Article.php on line 47

I have already tried replacing '@' whith ')', but it still doesn't work. If I do so, the error becomes:

Parse error: syntax error, unexpected ':' in C:\xampp\htdocs\cms\classes\Article.php on line 47

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'];
  }

I want it to run without any issues.

mysql123
  • 5
  • 5

1 Answers1

0

You should escape double quotes like this: \", just add the slash before.

The problem on lines 7 and 8. This code works for me.

    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'];
  }
Viktor
  • 188
  • 7