Гость
Целевая тема:
Создать новую тему:
Автор:
Форумы / PHP, Perl, Python [игнор отключен] [закрыт для гостей] / Sitemap php / 15 сообщений из 15, страница 1 из 1
24.08.2015, 11:24
    #39034812
Sitemap php
Здравствуйте ребята, помогите пожалуйста переделать скрипт так, что-бы он сайтмап сгенерировал и сохранил в файл.
Код: php
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
<?php
/**
  *
  * This is a quick way to turn a simple text file
  * with a list of urls in a text file (sitemap-urls.txt)
  * into a valid XML Sitemap:
  * http://en.wikipedia.org/wiki/Sitemaps
  * Put this file sitemap.xml.php and sitemap-urls.txt at
  * the webroot http://example.com/sitemap.xml.php
  * Then add the text in quotes below to your robots.txt file as a new line:
  * "Sitemap: http://example.com/sitemap.xml.php"
  * Questions? email joe@artlung.com
  */
$filename = 'sitemap-urls.txt';
$urls = file($filename);
$filectime = filectime($filename);
$urls = array_map('trim',$urls);
$sitemap = array();
foreach($urls as $url) {
	if ($url != '') {
		$priority = '0.5';
		$sitemap[] = array(
			'loc' => $url,
			'lastmod' => date('Y-m-d',$filectime),
			'changefreq' => 'weekly',
			'priority' => $priority,
		);
	}
}
header('Content-Type: text/xml');
echo '<?xml version=\'1.0\' encoding=\'UTF-8\'?>';
echo "\n";
echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9
			    http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">';
echo "\n";
foreach ($sitemap as $link) {
	echo "\t<url>\n";
	echo "\t\t<loc>" . htmlentities($link['loc']) . "</loc>\n";
	echo "\t\t<lastmod>{$link['lastmod']}</lastmod>\n";
	echo "\t\t<changefreq>{$link['changefreq']}</changefreq>\n";
	echo "\t\t<priority>{$link['priority']}</priority>\n";
	echo "\t</url>\n";
}
echo '</urlset>';
?>



Спасибки!
...
Рейтинг: 0 / 0
24.08.2015, 11:28
    #39034816
SharuPoNemnogu
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Sitemap php
Код: php
1.
$mapContent = '';

Далее все echo заменить на
Код: php
1.
$mapContent .=

и в конце
Код: php
1.
file_put_contents(<путь до корня сайта>'/sitemap.xml', $mapContent);
...
Рейтинг: 0 / 0
24.08.2015, 11:58
    #39034846
Sitemap php
SharuPoNemnogu, вот спасибки вам огромное!
Доброго Вам денёчка!
...
Рейтинг: 0 / 0
28.08.2015, 21:24
    #39038898
Sitemap php
Ребята Здравствуйте!
Код: xml
1.
2.
3.
4.
This page contains the following errors:

error on line 73 at column 66: Entity 'Auml' not defined
Below is a rendering of the page up to the first error.


Помогите пожалуйста,при генерации по этому коду, если в sitemap-urls.txt ,будет на пример польский язык, то сайтмап не работает, потому как я понимаю энтерпритарор xml неправильно эти символы распознает и сайтмап не открывается...
например вот так:
sÄ…cz-godziny-otwarcia
а в исходнике так
sącz-godziny-otwarcia
то есть в данном случае проблема с символом ą
Вот даже в посте тут эти символы идут как вопросительный знак, а на самом деле он выглядит как буква а с закарючкой снизу...

подскажите как это можно исправить???
...
Рейтинг: 0 / 0
28.08.2015, 22:39
    #39038926
SharuPoNemnogu
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Sitemap php
приложите пример исходных данных
...
Рейтинг: 0 / 0
29.08.2015, 12:19
    #39039099
Sitemap php
SharuPoNemnogu,
Здравствуйте!
Приложила пример файла исходника, а вот код получившейся карты:
Код: xml
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
<?xml version='1.0' encoding='UTF-8'?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9
			    http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
	<url>
		<loc>http://site.ru/&#197;&#188;yrafa-pozyczki/</loc>
		<lastmod>2015-08-29</lastmod>
		<changefreq>weekly</changefreq>
		<priority>0.5</priority>
	</url>
	<url>
		<loc>http://site.ru/pozyczka-od-reki-poznan/</loc>
		<lastmod>2015-08-29</lastmod>
		<changefreq>weekly</changefreq>
		<priority>0.5</priority>
	</url>
	<url>
		<loc>http://site.ru/po&#197;&#188;yczka-prywatna-pod-2013/</loc>
		<lastmod>2015-08-29</lastmod>
		<changefreq>weekly</changefreq>
		<priority>0.5</priority>
	</url>
	<url>
		<loc>http://site.ru/jastrz&#196;&#65533;bie-zdr&#195;&#179;j/</loc>
		<lastmod>2015-08-29</lastmod>
		<changefreq>weekly</changefreq>
		<priority>0.5</priority>
	</url>
	<url>
		<loc>http://site.ru/po&#197;&#188;yczka-sp-zoo/</loc>
		<lastmod>2015-08-29</lastmod>
		<changefreq>weekly</changefreq>
		<priority>0.5</priority>
	</url>
	<url>
		<loc>http://site.ru/po&#197;&#188;yczka-bez-bik/</loc>
		<lastmod>2015-08-29</lastmod>
		<changefreq>weekly</changefreq>
		<priority>0.5</priority>
	</url>
</urlset>
...
Рейтинг: 0 / 0
29.08.2015, 12:22
    #39039100
Sitemap php
почему-то файл не вижу, хотя прикрепила...
вообщем он такого содержания
Код: xml
1.
2.
3.
4.
5.
6.
http://site.ru/&#380;yrafa-pozyczki/
http://site.ru/pozyczka-od-reki-poznan/
http://site.ru/po&#380;yczka-prywatna-pod-2013/
http://site.ru/jastrz&#281;bie-zdr&#243;j/
http://site.ru/po&#380;yczka-sp-zoo/
http://site.ru/po&#380;yczka-bez-bik/


кодировка UTF-8(без BOM)
...
Рейтинг: 0 / 0
29.08.2015, 12:28
    #39039103
Sitemap php
вот...по другому почему-то не получается!
...
Рейтинг: 0 / 0
29.08.2015, 12:29
    #39039105
Sitemap php
даже ссылку не могу вставить... хттп+двоиточие+дваслэша-www.sendspace.com/file/v7hj7n
...
Рейтинг: 0 / 0
29.08.2015, 12:36
    #39039110
Sitemap php
Зарегистрировалась!)))
...
Рейтинг: 0 / 0
29.08.2015, 17:33
    #39039172
SharuPoNemnogu
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Sitemap php
Катеринка-К,

конкретно к этим данным
Код: php
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
function encodeUrl($url)
{
    $urlParse = parse_url($url);

    if (!(empty($urlParse['path']) || $urlParse['path'] == '/')) {
        $pathParts = array_map(
            function($v) {
                return !empty($v) ? urlencode($v) : null;
            },
            explode('/', $urlParse['path'])
        );

        $path = implode('/', array_filter($pathParts));

        $result = "{$urlParse['scheme']}://{$urlParse['host']}/{$path}";
    } else {
        $result = $url;
    }

    return $result;
}


и заменить
Код: php
1.
htmlentities($link['loc'])


на
Код: php
1.
encodeUrl($link['loc'])


пример
Код: php
1.
encodeUrl('http://site.ru/jastrz&#281;bie-zdr&#243;j/'); // return http://site.ru/jastrz%C4%99bie-zdr%C3%B3j
...
Рейтинг: 0 / 0
29.08.2015, 19:44
    #39039205
Sitemap php
SharuPoNemnogu,
Здравствуйте, спасибо Вам большое за помощь...
но я честно говоря не понимаю что изменилось...то есть я я функцию вставила и замену сделала
Код: php
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
<?php
/**
  *
  * This is a quick way to turn a simple text file
  * with a list of urls in a text file (sitemap-urls.txt)
  * into a valid XML Sitemap:
  * http://en.wikipedia.org/wiki/Sitemaps
  * Put this file sitemap.xml.php and sitemap-urls.txt at
  * the webroot http://example.com/sitemap.xml.php
  * Then add the text in quotes below to your robots.txt file as a new line:
  * "Sitemap: http://example.com/sitemap.xml.php"
  * Questions? email joe@artlung.com
  */
$filename = 'sitemap-urls.txt';
$mapContent = '';
$urls = file($filename);
$filectime = filectime($filename);
$urls = array_map('trim',$urls);
$sitemap = array();
foreach($urls as $url) {
	if ($url != '') {
		$priority = '0.5';
		$sitemap[] = array(
			'loc' => $url,
			'lastmod' => date('Y-m-d',$filectime),
			'changefreq' => 'weekly',
			'priority' => $priority,
		);
	}
}
function encodeUrl($url)
{
    $urlParse = parse_url($url);

    if (!(empty($urlParse['path']) || $urlParse['path'] == '/')) {
        $pathParts = array_map(
            function($v) {
                return !empty($v) ? urlencode($v) : null;
            },
            explode('/', $urlParse['path'])
        );

        $path = implode('/', array_filter($pathParts));

        $result = "{$urlParse['scheme']}://{$urlParse['host']}/{$path}";
    } else {
        $result = $url;
    }

    return $result;
}
header('Content-Type: text/xml');
$mapContent .= '<?xml version=\'1.0\' encoding=\'ISO 8859-16 \'?>';
$mapContent .= "\n";
$mapContent .= '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9
			    http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">';
$mapContent .= "\n";
foreach ($sitemap as $link) {
	$mapContent .= "\t<url>\n";
	$mapContent .= "\t\t<loc>" . encodeUrl($link['loc']) . "</loc>\n";
	$mapContent .= "\t\t<lastmod>{$link['lastmod']}</lastmod>\n";
	$mapContent .= "\t\t<changefreq>{$link['changefreq']}</changefreq>\n";
	$mapContent .= "\t\t<priority>{$link['priority']}</priority>\n";
	$mapContent .= "\t</url>\n";
}
$mapContent .= '</urlset>';
file_put_contents('sitemap.xml', $mapContent);
?>



на выходе получила sitemap.TXT и вот с такимиже закарючками как Вы и позали:
Код: xml
1.
// return http://site.ru/jastrz%C4%99bie-zdr%C3%B3j
...
Рейтинг: 0 / 0
29.08.2015, 21:56
    #39039230
SharuPoNemnogu
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Sitemap php
вставьте "закорючки" в браузер и посмотрите во что он их преобразует.
htmlentities
urlencode
кстати, ее лучше заменить на rawurlencode
...
Рейтинг: 0 / 0
31.08.2015, 02:47
    #39039489
Sitemap php
SharuPoNemnogu,
Вы правы, браузер все отрабатывает как надо!
Спасибки Вам огромное!
Ура Ура Ура!
...
Рейтинг: 0 / 0
04.09.2015, 11:05
    #39043182
Горшков
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Sitemap php
Была подобная проблема, тоже помогли)
...
Рейтинг: 0 / 0
Форумы / PHP, Perl, Python [игнор отключен] [закрыт для гостей] / Sitemap php / 15 сообщений из 15, страница 1 из 1
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]