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 6337979
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T19:21:17+00:00 2026-05-24T19:21:17+00:00

I have this peace of code $doc = new DOMDocument(); $doc->loadHTML($article_header); $imgs = $doc->getElementsByTagName(‘img’);

  • 0

I have this peace of code

$doc = new DOMDocument();
$doc->loadHTML($article_header);

$imgs = $doc->getElementsByTagName('img');
foreach ($imgs as $img) {

     if(!$img->getAttribute('class')){
$src = $img->getAttribute('src');
$newSRC = str_replace('/img/', '/mini/', $src);
$img->setAttribute('src', $newSRC);
$article_header = $doc->saveXml();
            }
                    }

It works fine taking $article_header with some text and images and making some changes inside of it. Problem is that DOM adds it’s own code to my $article_header variable. There are some XML headers and etc…

Also because of the fact that it is an article editor and I can edit my article 10 times, each time I run this script it adds some xml statements so in the end after several runs my $article_header in mysql database looks like this

<?xml version="1.0" standalone="yes"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<!--?xml version="1.0" standalone="yes"?-->
<html><body><p>&#xA0;</p>&#xD;
<p>&#xA0;</p>&#xD;
<!--?xml version="1.0" standalone="yes"?-->&#xD;
<p>&#xA0;</p>&#xD;
<p>&#xA0;</p>&#xD;
<!--?xml version="1.0" standalone="yes"?-->&#xD;
<p>1<img src="sources/public/users/103/articles/2011-06-11/3/img/1170x1600.gif" alt="" width="528" height="722.0512820512821"/>f</p>&#xD;
<!--?xml version="1.0" standalone="yes"?--></body></html>

Question is how can I get rid of all this additional data which is making me problems , because of this my article starts lower and lower becase this code is making multiple <br> effect.

  • 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-24T19:21:18+00:00Added an answer on May 24, 2026 at 7:21 pm

    you should use saveHTML() instead of saveXML()

    details — http://php.net/manual/en/domdocument.savehtml.php

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

Sidebar

Related Questions

I have this peace of code which brings string searches for img tags in
Guys I have this peace of code I'm using phonegap with jqueryMobile to develop
I have a weirdest thing, in this peace of code a browser adds tags
peace folks, I have this small piece of jquery based code, that grabs all
I have this code in jQuery, that I want to reimplement with the prototype
I have this string 'john smith~123 Street~Apt 4~New York~NY~12345' Using JavaScript, what is the
I have an XML doc with a structure like this: <Book> <Title title=Door Three/>
EDIT: This peace of code is pretty fine (so take it as example of
This code: string[] files = {test.txt, test2.txt, notes.txt, notes.doc, data.xml, test.xml, test.html, notes.txt, test.as};
I am using this peace of PHP code to save and rename some images.

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.