99use PHPHtmlParser \Dom \AbstractNode ;
1010use PHPHtmlParser \Dom \Collection ;
1111use PHPHtmlParser \Dom \HtmlNode ;
12+ use PHPHtmlParser \Dom \Tag ;
1213use PHPHtmlParser \Dom \TextNode ;
1314use PHPHtmlParser \DTO \TagDTO ;
1415use PHPHtmlParser \Enum \StringToken ;
@@ -171,10 +172,10 @@ public function loadStr(string $str, ?Options $options = null): Dom
171172 {
172173 $ this ->options = new Options ();
173174 if ($ this ->globalOptions !== null ) {
174- $ this ->options ->setFromOptions ($ this ->globalOptions );
175+ $ this ->options = $ this -> options ->setFromOptions ($ this ->globalOptions );
175176 }
176177 if ($ options !== null ) {
177- $ this ->options ->setFromOptions ($ options );
178+ $ this ->options = $ this -> options ->setFromOptions ($ options );
178179 }
179180
180181 $ this ->rawSize = \strlen ($ str );
@@ -194,7 +195,7 @@ public function loadStr(string $str, ?Options $options = null): Dom
194195 /**
195196 * Sets a global options array to be used by all load calls.
196197 *
197- * @chainable
198+ *
198199 */
199200 public function setOptions (Options $ options ): Dom
200201 {
@@ -512,11 +513,7 @@ private function parse(): void
512513 */
513514 private function parseTag (): TagDTO
514515 {
515- $ return = [
516- 'status ' => false ,
517- 'closing ' => false ,
518- 'node ' => null ,
519- ];
516+ $ return = [];
520517 if ($ this ->content ->char () != '< ' ) {
521518 // we are not at the beginning of a tag
522519 return new TagDTO ();
@@ -549,12 +546,20 @@ private function parseTag(): TagDTO
549546 $ return ['tag ' ] = \strtolower ($ tag );
550547
551548 return new TagDTO ($ return );
552- }
553-
554- $ tag = \strtolower ($ this ->content ->copyByToken (StringToken::SLASH (), true ));
555- if (\trim ($ tag ) == '' ) {
556- // no tag found, invalid < found
557- return new TagDTO ();
549+ } elseif ($ this ->content ->char () == '? ' ) {
550+ // special setting tag
551+ $ tag = $ this ->content ->fastForward (1 )
552+ ->copyByToken (StringToken::SLASH (), true );
553+ $ tag = (new Tag ($ tag ))
554+ ->setOpening ('<? ' )
555+ ->setClosing (' ?> ' )
556+ ->selfClosing ();
557+ } else {
558+ $ tag = \strtolower ($ this ->content ->copyByToken (StringToken::SLASH (), true ));
559+ if (\trim ($ tag ) == '' ) {
560+ // no tag found, invalid < found
561+ return new TagDTO ();
562+ }
558563 }
559564 $ node = new HtmlNode ($ tag );
560565 $ node ->setHtmlSpecialCharsDecode ($ this ->options ->isHtmlSpecialCharsDecode ());
@@ -631,23 +636,22 @@ private function parseTag(): TagDTO
631636 }
632637
633638 $ this ->content ->skipByToken (StringToken::BLANK ());
634- $ tag = \strtolower ($ tag );
635639 if ($ this ->content ->char () == '/ ' ) {
636640 // self closing tag
637641 $ node ->getTag ()->selfClosing ();
638642 $ this ->content ->fastForward (1 );
639- } elseif (\in_array ($ tag , $ this ->options ->getSelfClosing (), true )) {
643+ } elseif (\in_array ($ node -> getTag ()-> name () , $ this ->options ->getSelfClosing (), true )) {
640644 // Should be a self closing tag, check if we are strict
641645 if ($ this ->options ->isStrict ()) {
642646 $ character = $ this ->content ->getPosition ();
643- throw new StrictException ("Tag ' $ tag ' is not self closing! (character # $ character) " );
647+ throw new StrictException ("Tag ' " . $ node -> getTag ()-> name (). " ' is not self closing! (character # $ character) " );
644648 }
645649
646650 // We force self closing on this tag.
647651 $ node ->getTag ()->selfClosing ();
648652
649653 // Should this tag use a trailing slash?
650- if (\in_array ($ tag , $ this ->options ->getNoSlash (), true )) {
654+ if (\in_array ($ node -> getTag ()-> name () , $ this ->options ->getNoSlash (), true )) {
651655 $ node ->getTag ()->noTrailingSlash ();
652656 }
653657 }
0 commit comments