|
|
|
| Помогите пожалуйста загнать таблицу с http://www.bank.gov.ua/control/uk/curmetal/detail/currency?period=daily в массив. Знаю, что нужно сначала загрузить страницу, а потом регулярным выражением выбрать значения через preg_match_all, но вот реализовывать к сожалению не умею.Помогите пожалуйста. | |
|
|
|
|
|
|
|
для: Port_Artur
(30.08.2012 в 23:11)
| | Страницу занёс в переменную, а что дальше?
<?php
$content = get_content();
function get_content()
{
// Формируем ссылку
$link = "http://www.bank.gov.ua/control/uk/curmetal/detail/currency?period=daily";
// Загружаем HTML-страницу
$fd = fopen($link, "r");
$text="";
if (!$fd) echo "Запрашиваемая страница не найдена";
else
{
// Чтение содержимого файла в переменную $text
while (!feof ($fd)) $text .= fgets($fd, 4096);
}
// Закрыть открытый файловый дескриптор
fclose ($fd);
return $text;
}
?>
|
| |
|
|
|
|
|
|
|
для: Port_Artur
(30.08.2012 в 23:38)
| |
<?php
$file=file_get_contents("http://www.bank.gov.ua/control/uk/curmetal/detail/currency?period=daily");
preg_match(" /(курс яких змінюється.+<\/table>).+<\/table>/us",$file,$out);
preg_match_all("/<tr>.+?<\/tr>/us",$out[0],$out1);
$count=count($out1[0]);
for($i=1;$i<$count;$i++){
echo $out1[0][$i]."<br>------<br>";
}
?>
|
То есть, то, что вам нужно, находится в массиве $out1[0] | |
|
|
|
|
|
|
|
для: Port_Artur
(30.08.2012 в 23:11)
| |
<?
include 'simple_html_dom.php';
$html = file_get_html("http://www.bank.gov.ua/control/uk/curmetal/detail/currency?period=daily");
$html = $html->find('table',5);
$a = array();
foreach($html->find('tr') as $tr) {
foreach($tr->find('td') as $td) $a[] = $td->plaintext;
}
$html->clear();
unset($html);
echo '<pre>';
$a = array_chunk($a, 5);
print_r($a);
|
Библиотеку simple_html_dom.php качаем отсюда. | |
|
|
|
|
|
|
|
для: confirm
(31.08.2012 в 09:19)
| | Большое спасибо. Особенно за последний пример. | |
|
|
|