hey guys,
a php variable $htmlholds the following object…
<object width="562" height="200">
<param name="movie" value="http://www.youtube.com/v/rBa5qp9sUOY?version=3">
<param name="allowFullScreen" value="true">
<param name="allowscriptaccess" value="always">
<embed src="http://www.youtube.com/v/rBa5qp9sUOY?version=3"
type="application/x-shockwave-flash"
width="562"
height="200"
allowscriptaccess="always"
allowfullscreen="true">
</object>
any idea how I could filter the width and height both of the object- and embed-tag to have 100% values?
<object width="100%" height="100%">
...
<embed src="http://www.youtube.com/v/rBa5qp9sUOY?version=3"
type="application/x-shockwave-flash"
width="100%"
height="100%"
allowscriptaccess="always"
allowfullscreen="true">
</object>`
Thanks for your help!
update:
$chunk = $dom->getElementsByTagName('body')->item(0);
$objectHtml = '';
foreach($chunk->childNodes as $node) {
$objectHtml .= $node->saveXML();
}
return $objectHtml;
says: Call to undefined method DOMElement::saveXML()
whereas…
$dom = preg_replace('/^<!DOCTYPE.+?>/', '', str_replace( array('<html>', '</html>', '<body>', '</body>'), array('', '', '', ''), $dom->saveXML()));
works fine! however I get weird
inserted in my sourcecode when using this..
like this:
<!--?xml version="1.0" standalone="yes"?-->
<br>
<br>
<object width="95%" height="75%"><param name="movie" value="http://www.youtube.com/v/rBa5qp9sUOY?version=3"><param name="allowFullScreen" value="true"><param name="allowscriptaccess" value="always"><embed src="http://www.youtube.com/v/rBa5qp9sUOY?version=3" type="application/x-shockwave-flash" width="95%" height="75%" allowscriptaccess="always" allowfullscreen="true"></object>
any idea what I’m doing wrong here?
It is often better to use a HTML parser instead of a regex when modifying HTML.
You probably don’t want the element wrapped in
body, so do this…Where
$chunkis$dom->getElementsByTagName('body')->item(0).I added the option
LIBXML_NOEMPTYTAG, otherwise if you have<span></span>it will be turned into<span />.If using >= PHP 5.3, use
saveHTML()instead.