1

I'm trying to do the following:

$string = "<object width=\"425\" height=\"350\">
               <param name=\"movie\" value=\"http://www.youtube.com/v/1OtdDqF5rnI&autoplay=0\"></param>
               <param name=\"wmode\" value=\"transparent\"></param>
               <embed src=\"http://www.youtube.com/v/1OtdDqF5rnI&autoplay=0\" type=\"application/x-shockwave-flash\" wmode=\"transparent\" width=\"425\" height=\"350\"></embed>
           </object>";

$doc = new DOMDocument();
$doc->loadXML($string);

When I load the string i get the following errors:

[phpBB Debug] PHP Notice: in file /mnt/FS-2/Critical/Media/Private/Website/Online/blitz1up.com/application/controllers/articles.php on line 303: DOMDocument::loadXML() [domdocument.loadxml]: EntityRef: expecting ';' in Entity, line: 2
[phpBB Debug] PHP Notice: in file /mnt/FS-2/Critical/Media/Private/Website/Online/blitz1up.com/application/controllers/articles.php on line 303: DOMDocument::loadXML() [domdocument.loadxml]: EntityRef: expecting ';' in Entity, line: 4

I have narrowed the cause down to the YouTube URLs but am unsure of the best method to resolve this error. So any suggestions would be most welcome.

1 Answer 1

2

The URLs contain ampersands, which should be encoded as &amp; when not used for declaring entities. The parser assumes &autoload will start a new entitiy but it is never terminated with a semicolon.

For working with the HTML, consider loading the fragment with loadHTML(); and disable errors for that part:

libxml_use_internal_errors(TRUE);
$doc = new DOMDocument();
$doc->loadHTML($string);
libxml_clear_errors();
echo $doc->saveHTML();

The above would work with loadXML too.

Sign up to request clarification or add additional context in comments.

1 Comment

Cool... changing the ampersands to &amp has fixed the issue. Thank you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.