|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2012-12-31 22:51 UTC] mail+php at requinix dot net
[2013-12-02 16:32 UTC] mike@php.net
-Status: Open
+Status: Feedback
[2013-12-02 16:32 UTC] mike@php.net
[2014-12-30 10:41 UTC] php-bugs at lists dot php dot net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Dec 08 18:00:01 2025 UTC |
Description: ------------ I am trying to generate xml file for sitemap for google tracking of my site url. I have a php file with the code mentioned(Please refer the code sent) which I am running on the command line with no arguments. The code retrieves value in an array $venueArrayfrom the value recieved from the function $venue->getAll() There is a foreach loop which retrieves the value from the array '$venueArray'. In the foreach loop I have added a code to fetch url from array '$venueArray' element 'id':- $mainurl =$venue->getUrl(array("venueId"=>$venueD['id'])); and puts it in the xml tags with the help of the code $url->addchild("loc",$mainurl); and then the contents are appended in the file. It seems that some of the urls are not added (url for example: http://mysite.com/dresden/769112-venue-theater-wechselbad-großer-saal) in the following code intended to add urls:- $url->addchild("loc",$mainurl); Please provide me with the solution to my problem as soon as possible and also please let me know the changes which I should do in order to get urls in my xml file. Some of the urls are not added in $url->addchild("loc",$mainurl); Test script: --------------- <?php /** some of the urls are not added in $url->addchild("loc",$mainurl); **/ $xmltext = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\"></urlset>"; $xmlobj = simplexml_load_string($xmltext); /** Code to retrieve venue array **/ $venue = new record(); $venueArray=$venue->getAll(); /** End of the Code to retrieve venue array **/ foreach($venueArray as $venueD){ /** Code to retrieve Url from venue array **/ $mainurl =$venue->getUrl(array("venueId"=>$venueD['id'])); /** Example of the url generated http://mysite.com/dresden/769112-venue-theater-wechselbad-großer-saal **/ $url= $xmlobj->addChild("url"); $url->addchild("loc",$mainurl); $url->addChild("lastmod",date('Y-m-d')); $url->addChild("changefreq","daily"); $url->addChild("priority","0.9"); $fp=fopen('test.xml',"a"); fwrite($fp,$xmlobj->asXML()); fclose($fp); } ?> Expected result: ---------------- <?xml version="1.0" encoding="UTF-8" standalone="no"?> <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> <url> <loc>http://mysite.com/dresden/769112-venue-theater-wechselbad-großer- saal</loc> <lastmod>2012-12-21</lastmod> <changefreq>daily</changefreq> <priority>0.9</priority> </url> </urlset> Actual result: -------------- <?xml version="1.0" encoding="UTF-8" standalone="no"?> <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> <url> <loc/> <lastmod>2012-12-21</lastmod> <changefreq>daily</changefreq> <priority>0.9</priority> </url> </urlset>