B
B
Bur Ov2016-03-27 22:02:43
PHP
Bur Ov, 2016-03-27 22:02:43

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

The file is created but it is empty

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Aksentiev, 2016-03-27
@Sanasol

lied...
where does fwrite go?
int fwrite ( resource $handle , string $string [, int $length ] )
Where is a resource pointer

A
Andrey Molchanov, 2016-03-27
@johny_cat

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 question

Ask a Question

731 491 924 answers to any question