rango996
Ответы в темах
-
Форум: Проблемы и решения
Тема: Как запустить свой php в шаблоне WP?Всем спасибо. Вывел так
<?php include 'banner.php';?>
Форум: Проблемы и решения
Тема: Не работает парсинг погоды через XMLНе работает как в header так и в теле статьи при установленном плагине exec-php. Вообщем не знаю на что думать. Вот курсы валют без проблем спарсились. Вот собственно код парсинга валют для сравнения `<?php
$cache_lifetime = 3600; //в секундах, 3600=1 час
$cache_file = «cache/cache.html»; // в папке cache будет создаваться закешированный файл cache.html
$cache_content = false;
if ( file_exists($cache_file) ) {
$cache_modified = time() — @filemtime($cache_file);
if ( $cache_modified < $cache_lifetime ) {
$cache_content = file_get_contents($cache_file);
}}$date = date(«d.m.Y»); // Сегодня
$dom = new domDocument(«1.0», «cp1251»);
$dom->loadXML(file_get_contents(«http://www.cbr.ru/scripts/XML_daily.asp?date_req=$date»));
$root = $dom->documentElement;
$childs = $root->childNodes;
$data = array();
for ($i = 0; $i < $childs->length; $i++) {
$childs_new = $childs->item($i)->childNodes;
for ($j = 0; $j < $childs_new->length; $j++) {
$el = $childs_new->item($j);
$code = $el->nodeValue;
// Указываем нужные нам валюты, полный список их можно получить в файле http://www.cbr.ru/scripts/XML_daily.asp?date_req= в поле <CharCode>…</CharCode>
if ( $cache_content === false ) { ob_start();
$cache_content = $content;
ob_end_clean();
$fp = @fopen($cache_file, «w»);
if ( $fp ) {
@fwrite($fp, $cache_content);
@fclose($fp);
}}
echo $cache_content;if (($code == «USD») || ($code == «EUR»)) $data[] = $childs_new;
}
}
for ($i = 0; $i < count($data); $i++) {
$list = $data[$i];
for ($j = 0; $j < $list->length; $j++) {
$el = $list->item($j);
if ($el->nodeName == «CharCode») echo $el->nodeValue.» — «;
elseif ($el->nodeName == «Value») echo $el->nodeValue.»<br />»;
}
}
?>`Форум: Проблемы и решения
Тема: Не работает парсинг погоды через XML<?php $pogoda = file_get_contents('https://export.yandex.ru/bar/reginfo.xml?region=$city_10646.xml'); preg_match('/<weather_type>(.*?)<\/weather_type>/i',$pogoda,$type); preg_match('/<temperature class_name="t4" color="F1F0E9">(.*?)<\/temperature>/i',$pogoda,$temp); preg_match('/<image-v3 size="48">(.*?)<\/image-v3>/i',$pogoda,$img2); $vivod = "<img align=\"top\" src=\"$img2[1]\" alt=\"$type[1]\" />$temp[1] °C $type[1] "; echo $vivod; ?>