D
D
Dmitry Krylov2017-04-18 00:49:12
PHP
Dmitry Krylov, 2017-04-18 00:49:12

How can the parser be improved?

At the moment, the parser is parsing the entire UpTime string. (including words about the time the site worked without errors). What should be changed in the parser so that it displays only the uptime value and nothing more? Attached is the parser code.

<?php
function browser($url) {
$url="http://ping-admin.ru/free_uptime/stat/761d80929682cbfc470a4a9322dd5b109541.html";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)");
$html = curl_exec($ch);
curl_close($ch);
return $html;
}
preg_match_all('~<td class="lst">(.*?)</td>~is', browser($url), $text);
print implode('<br />', array_slice($text[1], 1, 1)); //вывод строки UpTime
?>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
DevMan, 2017-04-18
@CyberMan1324

replace

print implode('<br />', array_slice($text[1], 1, 1)); // вообще ересь
to play around with the format to taste, php.net/manual/ru/function.sprintf.php

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question