0

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 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.

Community
  • 1
  • 1
Rekha
  • 403
  • 2
  • 14
  • 26

2 Answers2

2

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.

2ndkauboy
  • 9,136
  • 2
  • 28
  • 62
1

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

João Pimentel Ferreira
  • 11,565
  • 7
  • 67
  • 91