From 5d1081c1b366ed764e32d6e11f621ae81576cf30 Mon Sep 17 00:00:00 2001 From: mirivlad Date: Mon, 21 Aug 2023 09:57:06 +0300 Subject: [PATCH] Change method request quotes from ipfw.ru/bash --- parse.php | 55 +++++++++++++++++++++++++++---------------------------- 1 file changed, 27 insertions(+), 28 deletions(-) diff --git a/parse.php b/parse.php index e246919..b3d12a0 100644 --- a/parse.php +++ b/parse.php @@ -9,40 +9,39 @@ function getElementByClassname ($html, $classname) { $tmp_dom = new DOMDocument(); foreach ($nodes as $node) { $tmp_dom->appendChild($tmp_dom->importNode($node, true)); + break; } return trim($tmp_dom->saveHTML()); } -$quote = ""; + $random = rand()&1; +$url= ''; +$pre_quote = ''; +$quote = ""; +$class = ''; + if ($random == 0){ - $file=file_get_contents("http://ipfw.ru/bash/fortune"); - $file = mb_convert_encoding($file, 'UTF-8', 'KOI8-R'); - $arr = explode ('%', $file); - array_splice($arr,0,3); - shuffle($arr); -//foreach ($arr as $fortune){ -// $fortune=nl2br($fortune); -//echo $fortune; -//echo "


"; -//} - $quote = "from ipfw.ru/bash:

".nl2br(htmlentities($arr[0])); - $quote = str_replace ("

","
", $quote); + $url = "http://ipfw.ru/bash/random"; + $pre_quote = "from ipfw.ru/bash:

"; + $class = "quotebody"; }else{ - $data = ""; - $curl = curl_init(); -// Set some options - we are passing in a useragent too here - curl_setopt_array($curl, array( - CURLOPT_RETURNTRANSFER => 1, - CURLOPT_URL => 'http://ibash.org.ru/random.php', - CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13' - )); -// Send the request & save response to $resp - $data = curl_exec($curl); -// Close request to clear up some resources - curl_close($curl); -//$data = mb_convert_encoding($data, 'UTF-8', 'windows-1251'); - $quote = "from iBASH:

".getElementByClassname($data, "quotbody"); + $url = "http://ibash.org.ru/random.php"; + $pre_quote = "from iBASH:

"; + $class = "quotbody"; } -//print_r ($arr); + $data = ""; + $curl = curl_init(); +// Set some options - we are passing in a useragent too here + curl_setopt_array($curl, array( + CURLOPT_RETURNTRANSFER => 1, + CURLOPT_URL => $url, + CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13' + )); +// Send the request & save response to $resp + $data = curl_exec($curl); +// Close request to clear up some resources + curl_close($curl); +//$data = mb_convert_encoding($data, 'UTF-8', 'windows-1251'); + $quote = $pre_quote.getElementByClassname($data, $class); ?>