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

  • Home
  • SEARCH
  • 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 7952781
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T02:57:43+00:00 2026-06-04T02:57:43+00:00

$dom = new DOMDocument(‘1.0’, ‘UTF-8’); $dom->loadHTML($content); $divs = $dom->getElementsByTagName(div); foreach ( $divs as $div

  • 0
$dom = new DOMDocument('1.0', 'UTF-8');
$dom->loadHTML($content);
$divs = $dom->getElementsByTagName("div");
foreach ( $divs as $div ) {
    if ( $class = $div->attributes->getNamedItem("class") ) {
        if ( $class->nodeValue == "simplegalleryholder" ) 
            $div->parentNode->removeChild( $div );
    }
}
$content = $dom->saveHTML();

This simple code should help me with removing

<div class="simplegalleryholder"> .... </div> 

from the document. The only problem is, that $content contains utf8 encoded special characters (ąęść etc), that are destroyed by proces (i get iÄ™ Å‚ ż instead).

How should I approach this issue to get correct result?

  • 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-06-04T02:57:46+00:00Added an answer on June 4, 2026 at 2:57 am

    Specifying UTF-8 in the constructor doesn’t make the underlying xml processing library process it as utf8. The following workaround is really hacky, but its works reasonably well.

    $encodingHint = '<meta http-equiv="Content-Type" content="text/html; charset=utf-8">';
    $dom->loadHTML($encodingHint . $html);
    

    https://bugs.php.net/bug.php?id=32547

    If you’re viewing the output in a web browser, send a real http header, not an http-equiv meta tag. This is only for viewing. processing with domdocument specifically needs the meta tag.

    header('content-type: text/html; charset=utf-8');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is piece of code $doc = new DOMDocument(); $doc->loadHTML($article_header); $imgs = $doc->getElementsByTagName('img'); foreach
I've got my HTML inside of $html . dom = new DOMDocument(); $dom->loadHTML($html); $xpath
I am getting an odd error when running $dom = new DOMDocument(1.0, utf-8);: Warning
I have this peace of code $doc = new DOMDocument(); $doc->loadHTML($article_header); $imgs = $doc->getElementsByTagName('img');
I have the following code: $doc = new DOMDocument(); $doc->loadHTML($quiz['value']); $imageElement = $doc->getElementsByTagName('img')->item(0); }
Private Sub Command1_Click() Dim dom As New DOMDocument Dim http As New XMLHTTP Dim
For example, I write a method: Private Sub Command1_Click() Dim dom As New DOMDocument
i am using following code $doc = new DOMDocument(); $doc->strictErrorChecking = false; @$doc->loadHTML($data); $xpath
i am using DOM to get content of div tag but inner html part
I have a problem with a php DOM Object http://php.net/manual/en/class.domdocument.php Is it possible only

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.