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

The Archive Base Latest Questions

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

<?php $books = array(); $books [] = array( ‘title’ => ‘PHP Hacks’, ‘author’ =>

  • 0
<?php                                               

  $books = array();
  $books [] = array(
  'title' => 'PHP Hacks',
  'author' => 'Jack Herrington',
  'publisher' => "O'Reilly"     
  );                            
  $books [] = array(            
  'title' => 'Podcasting Hacks',
  'author' => 'Jack Herrington',
  'publisher' => "O'Reilly"     
  );                            

  $doc = new DOMDocument();     
  $doc->formatOutput = true;    
  $r = $doc->createElement( "books" );
  $doc->appendChild( $r );            
  foreach( $books as $book )          
  {                                   
  $b = $doc->createElement( "book" ); 

  $author = $doc->createElement( "author" );
  $author->appendChild(
  $doc->createTextNode( $book['author'] )
  );
  #$author->appendChild( $doc->createTextNode( 'pavunkumar'));
  $new = $doc->createElement("Developer");
  $a=$doc->createTextNode('I am developer ' );
  $new->appendChild($a);
  $b->appendChild( $author );
  $b->appendChild($new);
  $b->appendChild($new);
  $title = $doc->createElement( "title" );
  $title->appendChild(
  $doc->createTextNode( $book['title'] )
  );
  $b->appendChild( $title );
  $publisher = $doc->createElement( "publisher" );
  $publisher->appendChild(
  $doc->createTextNode( $book['publisher'] )
  );
  $b->appendChild( $publisher );

  $r->appendChild( $b );
  }
  echo $doc->SaveXml() ;
  ?>

When I run this code in command line. I am getting following things

<?xml version="1.0"?>
<books>
  <book>
    <author>Jack Herrington</author>
    <Developer>I am developer </Developer>
    <title>PHP Hacks</title>
    <publisher>O'Reilly</publisher>
  </book>
  <book>
    <author>Jack Herrington</author>
    <Developer>I am developer </Developer>
    <title>Podcasting Hacks</title>
    <publisher>O'Reilly</publisher>
  </book>
</books>

When I run the code in web browser it gives me following things

Jack Herrington  I am developer  O'Reilly    Jack Herrington  I am developer  O'Reilly  

I want to above output to be like command line output. And one more things is that instead of displaying , how could I create a xml file using $doc Dom object.

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

    I may not be correct, but try sending a header like that:

    Header("Content-Type: text/xml");
    

    or

    Header("Content-Type: text/plain");
    

    to achieve appropriate results. (Of course before you run $doc->saveXML();.

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

Sidebar

Ask A Question

Stats

  • Questions 508k
  • Answers 508k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer SELECT TIME(start_time) AS start, TIME(end_time) AS end, TIME_TO_SEC(TIMEDIFF(end_time, start_time)) AS… May 16, 2026 at 4:17 pm
  • Editorial Team
    Editorial Team added an answer My project uses Spring a lot (core, web flow, security),… May 16, 2026 at 4:17 pm
  • Editorial Team
    Editorial Team added an answer Rails 3 was released last night!!! Let's get to work. May 16, 2026 at 4:17 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I use Postgresql + PHP. Say I have this table: Books ( id, title,
I've reading some books on advanced PHP, and most of the time I find
I am new to php and am asking for some coding help. I have
I am a little stuck on how to create this array. My data: category_id
PHP is my first programming language. I can't quite wrap my head around when
In php is there a function to increment the values of subsequent values twice(*2)
Level: PHP Learner I'm stuck with a checkbox problem. I have a db that
I'm not sure if the array is too deep or what, but I can't
I was wondering how to do the PHP OOP design pattern for real life
My question is straight forward. I'm totally new to the Microsoft stack, I have

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.