tags:

views:

13

answers:

1

Hello,

I'm trying to do the following:

$string = "<object width=\"425\" height=\"350\">
               <param name=\"movie\" value=\"http://www.youtube.com/v/1OtdDqF5rnI&amp;autoplay=0\"&gt;&lt;/param&gt;
               <param name=\"wmode\" value=\"transparent\"></param>
               <embed src=\"http://www.youtube.com/v/1OtdDqF5rnI&amp;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  A: 

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.

Gordon
diggersworld