Answer the question
In order to leave comments, you need to log in
How to save the generated xml to a file on the server?
I generate xml sitemap according to this manual -> artkiev. com/blog/php-generation-sitemap.htm (not advertising)
Displays the result in the browser - everything is fine prntscr.com/akrv3o
But how to save this result to the server in the sitemap.xml file?
Tried like this:
set_time_limit(0);
include("./sitemapclass.php");
$sitemap = new sitemap();
$sitemap->set_ignore(array("javascript:", ".css", ".js", ".ico", ".jpg", ".png", ".jpeg", ".swf", ".gif"));
$sitemap->get_links("http://test.ru");
header ("content-type: text/xml");
$map = $sitemap->generate_sitemap();
echo $map; // тут выводит на экран
----------------- тут как пробовал я ----------------------
// открываем файл, если файл не существует,
//делается попытка создать его
$fp = fopen("sitemap.xml", "w");
// записываем в файл текст
fwrite($map, $text);
// закрываем
fclose($fp);
Answer the question
In order to leave comments, you need to log in
lied...
where does fwrite go?
int fwrite ( resource $handle , string $string [, int $length ] )
Where is a resource pointer
You have a variable that displays the map is called $map
And you write the $text variable to the file, which you don't even have in the code.
It will be right:fwrite($fp, $map);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question