0

Possible Duplicate:
Getting SimpleXMLElement to include the encoding in output

PHP :

$xml = new SimpleXMLElement("<Title0></Title0>");
$xml->Title1='Some Text  1';
$output = $xml->asXML('mak.xml');

XML Output :

<?xml version="1.0"?>  
<Title0>
    <Title1>Some Text 1</Title1>
</Title0>

But I want to add attrbute like encoding="utf-8" to xml header , so that I can have something like this :

<?xml version="1.0" encoding="utf-8" ?>  
<Title0>
    <Title1>Some Text 1</Title1>
</Title0>

I dont want to use find and replace sort of things on the output file.

Community
  • 1
  • 1
Makesh
  • 1,236
  • 1
  • 11
  • 25
  • 3
    [This question](http://stackoverflow.com/questions/869650/getting-simplexmlelement-to-include-the-encoding-in-output) might help. – Mitya Jul 30 '12 at 13:44

1 Answers1

-3

Read this:--

http://php.net/manual/en/simplexml.examples-basic.php

try this:-

Example #10 Adding elements and attributes

<?php
include 'example.php';
$movies = new SimpleXMLElement($xmlstr);

$character = $movies->movie[0]->characters->addChild('character');
$character->addChild('name', 'Mr. Parser');
$character->addChild('actor', 'John Doe');

$rating = $movies->movie[0]->addChild('rating', 'PG');
$rating->addAttribute('type', 'mpaa');

echo $movies->asXML();
?>
Abid Hussain
  • 7,724
  • 3
  • 35
  • 53