justinomaha Posted February 11, 2010 Share Posted February 11, 2010 Hey everyone, I'm still learning PHP and this problem has been driving me nuts! I have a script that I'm trying to use to make sitemaps. The data is pulled from an xml file and not a mysql database. Basically, I'm trying to make the data using foreach and then saving it as an array. Then using a search and replace in my template file. I have no idea if I'm even close but the code below is my latest test... any ideas? foreach( $finalurl as $key => $value){ $sm_data .= "<url><loc>http://www.".$mainsiteurl.".com/".$finalurl."</loc>\n"; $sm_data .= "<changefreq>daily</changefreq><priority>0.9</priority></url>\n"; return $sm_data; } $replacethesesitemap = array('REPLACEDOMAIN'); $replacevaluessitemap = array($sm_data); $replaceeventsitemap = str_replace($replacethesesitemap, $replacevaluessitemap, $sitemaptemplate); //CREATE THE TEST.TXT FILE $myFilesitemap = "$root/test.txt"; $fhsitemap = fopen($myFilesitemap, 'w') or die("can't open file"); $stringDatasitemap = "$replaceeventsitemap"; fwrite($fhsitemap, $stringDatasitemap); fclose($fhsitemap); } Link to comment https://forums.phpfreaks.com/topic/191714-foreach-as-variable-help/ Share on other sites More sharing options...
trq Posted February 11, 2010 Share Posted February 11, 2010 Do you have an sm_data function defined anywhere? Link to comment https://forums.phpfreaks.com/topic/191714-foreach-as-variable-help/#findComment-1010502 Share on other sites More sharing options...
justinomaha Posted February 11, 2010 Author Share Posted February 11, 2010 I do not. I'm sorry, I forgot to delete that from the code. Link to comment https://forums.phpfreaks.com/topic/191714-foreach-as-variable-help/#findComment-1010503 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.