Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4267394
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T06:53:36+00:00 2026-05-21T06:53:36+00:00

hey guys, a php variable $html holds the following object… <object width=562 height=200> <param

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T06:53:37+00:00Added an answer on May 21, 2026 at 6:53 am

    It is often better to use a HTML parser instead of a regex when modifying HTML.

    $dom = new DOMDocument;
    
    $dom->loadHTML($str);
    
    $object = $dom->getElementsByTagName('object')->item(0);
    
    $object->setAttribute('width', '100%');
    $object->setAttribute('height', '100%');
    
    $embed = $object->getElementsByTagName('embed')->item(0);
    
    $embed->setAttribute('width', '100%');
    $embed->setAttribute('height', '100%');
    
    echo $dom->saveXML($dom->getElementsByTagName('body')->item(0));
    

    You probably don’t want the element wrapped in body, so do this…

    $objectHtml = '';
    foreach($chunk->childNodes as $node) {
        $objectHtml .= $dom->saveXML($node, LIBXML_NOEMPTYTAG);
    }
    

    Where $chunk is $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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

hey guys how to make these php html links codes possible. i have tried
Hey there guys and gals. I'm very new to php and am following various
hey guys, the following rule overwrites /signup.php with just /signup RewriteRule ^signup$ signup.php exactly
Hey guys How do I use the PHP variable $contact['id'] in my ajax call?
Hey guys, I'm using Twitter's PHP API, called twitterlibphp , and it works well,
hey guys, i'm getting an exception on the following inner exception: {Value cannot be
Hey guys I have an ajax jquery function that receives data from a php
Hey guys I have one php exec command that works on my remote linux
hey guys is this even possible to be done in php <?php $sectorcount =
Hey guys, question about regex in PHP! For the given pattern, kinda like a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.