0

I wish to include in an email the entire xml string (inlcuding headers, tags etc) as a backup to copy/paste. If I use the following:

<?php $xml_content = file_get_contents('http://www.w3schools.com/xml/note.xml'); echo $xml_content; ?>

It shows: Tove Jani Reminder Don't forget me this weekend!

Rather than the full string which would be:

<?xml version="1.0" encoding="ISO-8859-1"?>
<note> 
 <to>Tove</to> 
 <from>Jani</from> 
 <heading>Reminder</heading>
 <body>Don't forget me this weekend!</body>
</note>
1
  • 1
    It does return the full XML string. If you are viewing from a browser, try to view source. Commented Oct 8, 2013 at 9:26

2 Answers 2

3

You have to set the page content type to xml or plaintext if you want it to output the file entirely.

header('Content-Type: text/xml');

or if this doesn't work, then

header('Content-Type: text/plain');
Sign up to request clarification or add additional context in comments.

3 Comments

I mainly wish to import the xml and use it within PHP, will that mess that part up?
If you wish to import the XML to PHP, just do it. Your problem is a display issue when outputting the XML document onto an HTML page. Your browser is treating the XML elements, e.g. <note>, as if they're (unknown) HTML elements and not showing them. The PHP will receive the XML just fine.
Bear in mind that if you want to send the XML in an email, then either you'll need to make sure the email type is plain text, or, if it's HTML, encode the XML output so it displays okay, probably using htmlspecialchars() That would also work for outputting it onto an HTML page.
0

If you're looking to show the XML with tags in email, then you have to convert the special HTML tags to entities.

<?php
    $xml_content = file_get_contents('http://www.w3schools.com/xml/note.xml');
    echo htmlspecialchars($xml_content);
?>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.