0

I have a problem with DOMDocument class.

I need to pass to DOMDocument::createElement method HTML as a value of element.

I have, a class which builds a schedule for events and one method of this class have the code like that:

$label = $this->list->createElement('label', $this->getEventDescription($event));

Like you see I'm creating label with event description, but the structure of this description is dependent on event and sometimes includes other HTML tags such as <i> <span>. At the moment, when I do it the way above, the HTML code is not interpreted, but displayed as text, which is not my desired result.

Is it possible for the createElement method to interpret this html and create it as a node so that my getEventDescription method can still return a string?

I've been tried that:

$label = $this->list->createElement('label');
$description = new DOMDocument('1.0');
$description->loadHTML($this->getEventDescription($event));
$label->appendChild($description);

But it's failed because of Wrong Document Error

LordF
  • 253
  • 3
  • 15

0 Answers0