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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T23:14:16+00:00 2026-05-22T23:14:16+00:00

I am a beginner in PHP and XML. Can somebody tell me how to

  • 0

I am a beginner in PHP and XML.

Can somebody tell me how to include XML encoding when I write a new xml file.

Here are the codes:

writexml.php

<?php 
 $ids =  array("1", "2", "3", "4", "5");
 $names = array("Jean Claude Van Damme", "Scott Adkins", "Dolph Ludgren", "Michael Jai White", "Michael Worth");

 $domdoc = new DOMDocument(); 
 $domdoc->formatOutput = true; 

 $el_actionstars = $domdoc->createElement( "actionstars" ); 
 $domdoc->appendChild( $el_actionstars  ); 

 $arr_size = count($ids);

 for ($i=0; $i < $arr_size; $i++) {
  $el_actionstar = $domdoc->createElement( "actionstar" ); 

  $el_id =  $domdoc->createElement( "id" ); 
  $el_id->appendChild( $domdoc->createTextNode($ids[$i] . "")); 
  $el_actionstar->appendChild($el_id);

  $el_name =  $domdoc->createElement( "name" ); 
  $el_name->appendChild( $domdoc->createTextNode($names[$i] . "")); 
  $el_actionstar->appendChild($el_name);


  $el_actionstars->appendChild($el_actionstar);
 }

 echo $domdoc->saveXML(); 
 $domdoc->save("actionstars.xml") 
?>

The xml output is <?xml version="1.0"?> and I want to add the encoding to make it look like <?xml version="1.0" encoding="ISO-8859-1"?>. Pls help…

  • 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-22T23:14:17+00:00Added an answer on May 22, 2026 at 11:14 pm

    See bottom of http://php.net/manual/en/domdocument.savexml.php

    When you save whole document:
    DOMDocument->saveXML() produces string
    in encoding defined in property
    DOMDocument->encoding.

    When you save only one node:
    DOMDocument->saveXML(DOMNode) produces
    always string in UTF-8.

    You can set it in the constructor

    DOMDocument::__construct ([ string $version [, string $encoding ]] )
    

    e.g.,

    $domdoc = new DOMDocument('1.0', 'iso-8859-1');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am beginner in PHP. I am trying to parse this xml file. <relationship>
I am a beginner in PHP and I know nothing about XML manipulation. I
I'm a beginner at PHP, and I'm still trying to work out proper file
I am a beginner in PHP. How can I restrict user access to controller.php
I am a beginner in PHP and am working on a script that can
Given this XML file: <?xml version=1.0 encoding=UTF-8?> <root> <data> <track clipid=1> <url>http://www.emp3world.com/to_download.php?id=33254</url> <http_method>GET or
I'm a beginner and I really need your help! I have an XML file
I am just a beginner in php. I have tried to write code for
To start, I am a beginner with PHP and .htaccess. Here is my dilemma...
I'm a beginner with PHP security issues. Someone reported a security issue with my

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.