Jump to content

ForEach as Variable Help


justinomaha

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.