开发者

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 :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜