dynamically create sitemap xml using php
I have created sitemap for my site using some reference code in the below link
Creating an XML sitemap with PHP
But I am getting error as
XML Parsing Error: undefined entity Location:
as my content is开发者_JAVA技巧 as follows
<< alt >> attribute and it says something like
< loc >http://www.example.com/700- & laquo;alt & raquo;-attributes-in-images.php< /loc >
Can anyone tell me how to get rid of this error.
I think you just have to use the urlencode()
function on the link value and reconvert the entities before using html_entity_decode()
:
echo '<loc>'.urlencode(html_entity_decode($link)).'<loc>';
or something similar in your code.
The best solution is to have access to you root folder and add to your Apache .htaccess
file the following lines
RewriteEngine On
RewriteRule sitemap\.xml sitemap.php [L]
and then simply having a file sitemap.php
in your root folder that therefore would be normally accessible via http://yoursite.com/sitemap.xml
, the default URL where all search engines will firstly search.
That file sitemap.php
shall start with
<?php header('Content-type: application/xml; charset=utf-8') ?>
<?php echo '<?xml version="1.0" encoding="UTF-8"?>' ?>
I have this solution and it works like a charm :)
精彩评论