0

I am a novice and I work in PHP. And I do not know anything about xml. My English is not very good. If you see a typo, please edit it

Please see the code below

<?php 
header("Content-type: text/xml");
$array = ["a", "b", "c"];
echo $array[0];

There is a problem with the output and I can not use the echo. The photo below is my output

view photo

please guide me

0

2 Answers 2

1

I found out from the url that you want to create a sitemap. You should see the output inside a xml code. for example:

<?php 
header("Content-type: text/xml");
$array = ["a", "b", "c"];

echo "<?xml version='1.0' encoding='UTF-8'?>"."\n";
echo "<urlset xmlns='http://www.sitemaps.org/schemas/sitemap/0.9'>"."\n";
 echo "<url>";
 echo "<loc>".$array[0]."</loc>";
 echo "<lastmod>".$array[1]."</lastmod>";
 echo "<changefreq>daily</changefreq>";
 echo "</url>";
echo "</urlset>";
Sign up to request clarification or add additional context in comments.

Comments

1

If you are debugging, then comment out the header line. Once the content type header is set, output in that content type only. The browser is expecting a well formed xml. So just printing that out won't work.

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.