Пользователь пока ничего не рассказал о себе

Наибольший вклад в теги

Все теги (12)

Лучшие ответы пользователя

Все ответы (27)
  • График курса валют с ЦБ?

    @AdrianBlair
    7b174324610940d1b2fb1a80eea83ae3.png

    Делал на скорую руку

    <?php
    function get($url) {
    	$ch = curl_init();
    	curl_setopt($ch, CURLOPT_URL, $url);
    	curl_setopt ($ch, CURLOPT_TIMEOUT, 60);
    	curl_setopt ($ch, CURLOPT_RETURNTRANSFER, TRUE); 
    	curl_setopt ($ch, CURLOPT_FAILONERROR, true);
    	$data = curl_exec($ch);
    	echo curl_error($ch);
    	curl_close($ch);
    	return $data;
    }
    
    function url() {
    	$to = date("d/m/Y");
    	$d = date("d");
    	$m = date("m");
    	$y = date("Y") - 1;
    	$from = "$d/$m/$y";
    	$url = "http://www.cbr.ru/scripts/XML_dynamic.asp?date_req1=$from&date_req2=$to&VAL_NM_RQ=R01235";
    	return get($url);
    }
    
    function today($array) {
    	$max = count($array["Record"]) - 1;
    	$price = str_replace(",", ".", $array["Record"][$max]["Value"]);
    	return $price;
    }
    
    $content = url();
    
    $xml = simplexml_load_string($content);
    $json = json_encode($xml);
    $array = json_decode($json, TRUE);
    ?>
    <!DOCTYPE html>
    <html>
    <head>
        <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
        <script type="text/javascript">
    	google.charts.load('current', {'packages':['corechart']});
    	google.charts.setOnLoadCallback(drawChart);
    
    	function drawChart() {
    		var data = google.visualization.arrayToDataTable([
    			["Дата", "Стоимость"],
    <?
    for($i = 0; $i < count($array["Record"]); $i++) {
    	$date = date("d.m.Y", strtotime($array["Record"][$i]["@attributes"]["Date"]));
    	$price = str_replace(",", ".", $array["Record"][$i]["Value"]);
    	if($i == count($array["Record"]) - 1) {
    		echo "['$date', $price]\n";
    	} else {
    		echo "['$date', $price],\n";
    	}
    }
    ?>
    		]);
    
    		var options = {
    			vAxis: {minValue: <?=today($array)*1.1?>}
    		};
    
    		var chart = new google.visualization.AreaChart(document.getElementById("dollar"));
    		chart.draw(data, options);
    	}
        </script>
    	<style>
    	body {
    		width: 75vw;
    		margin: 3em auto;
    		font-family: Arial, sans-serif;
    		font-size: 16px;
    	}
    	
    	.title {
    		text-align: center;
    		color: #333;
    		width: 100%;
    		font-size: 2em;
    	}
    	
    	.dollar:before {
    		content: "Доллар: ";
    		font-size: 0.75em;
    	}
    	.dollar:after {
    		content: " ₽";
    		font-size: 0.75em;
    	}
    	</style>
    </head>
    <body>
    	<div class="title dollar"><?=today($array)?></div>
    	<div id="dollar" style="width: 100%; height: 500px;"></div>
    </body>
    </html>
    Ответ написан
    2 комментария
  • В чем проблема и почему?

    @AdrianBlair
    Javascript должен выполнится после полной загрузки страницы или во время загрузки, но не перед загрузкой...
    window.onload = function() {
    	new Vue({
    		el: "#one",
    		data: {
    			short: "Generally, most people prefer to buy gadgets early in the product’s life cycle, so it remains “new” for longer. Others prefer to buy a bit later, waiting for any early issues to be worked out. And everyone will agree, that buying right before a major improvement will make you feel at least slightly bitter, because Apple is not known for signalling a product update with a sale. Regardless of your preference, as an informed consumer you can make better purchase decisions. Over at MacRumors, they maintain an excellent Buyer’s Guide that keeps track of all Apple product upgrades. It’ll show you the date of the most recent upgrade, and the average number of days between previous updates to give you a rough idea of when you can expect something new. It also conveniently aggregates the latest rumors of what may come of the upgrade. Definitely consult with the Buyer’s Guide before dropping two grand on a laptop. Product updates can take two forms; updated internal components that result in performance gains, or a complete product redesign. Apple tipically upgrades Mac specifications once or (rarely) twice a year, these updates are predictable like clockwork. A complete product redesign occurs every few years and is harder to predict, it’s normally the subject of many rumors and leaks from the supply chain. The timing of any upgrades generally follows by the release of new processors from Intel.",
    			full: "Generally, most people prefer to buy gadgets early in the product’s life cycle, so it remains “new” for longer. Others prefer to buy a bit later, waiting for any early issues to be worked out. And everyone will agree, that buying right before a major improvement will make you feel at least slightly bitter, because Apple is not known for signalling a product update with a sale. Regardless of your preference, as an informed consumer you can make better purchase decisions. Over at MacRumors, they maintain an excellent Buyer’s Guide that keeps track of all Apple product upgrades. It’ll show you the date of the most recent upgrade, and the average number of days between previous updates to give you a rough idea of when you can expect something new. It also conveniently aggregates the latest rumors of what may come of the upgrade. Definitely consult with the Buyer’s Guide before dropping two grand on a laptop. Product updates can take two forms; updated internal components that result in performance gains, or a complete product redesign. Apple tipically upgrades Mac specifications once or (rarely) twice a year, these updates are predictable like clockwork. A complete product redesign occurs every few years and is harder to predict, it’s normally the subject of many rumors and leaks from the supply chain. The timing of any upgrades generally follows by the release of new processors from Intel. In the last couple of years Intel released a new generation of processors in the first half of the calendar year, and Apple incorporates these chips into updated Macs shortly thereafter. When there is a significant improvement, Apple holds special keynote presentations to present their latest creations. Minor specs bumps however, can be released quietly released in a press release. This year, it’s been reported that Intel will be releasing their brand new family of Haswell processors on June 3rd, 2013. It is therefore widely anticipated that new Macs will be arriving following Apple’s Worldwide Developers Conference (WWDC) on June 10th. New MacBooks! Yay! Can you tell I’m the early adopter? Mac hardware refreshes follow a mostly predictable timeline, this allows the educated consumer to plan their purchase. The same is true for iPhones and iPads, after the annual update pattern is established, Apple will rarely deviate from that path."
    		}
    	})
    }
    Ответ написан
    2 комментария
  • Работа с .txt | Как взять и удалить строку?

    @AdrianBlair
    Алгоритм не пробовал составить?

    Создал файл index.php:
    <?php
    $str = $_GET["str"];
    $idtxt = "id.txt";
    $resulttxt = "result.txt";
    if ($str != "") {
    	$str--;
    	$file = file($idtxt);
    	$fp = fopen($idtxt,"w");
    	for($i = 0; $i < sizeof($file); $i++) {
    		if($i == $str) {
    			$array = $file;
    			$sid =  $array[$i];
    			unset($file[$i]);
    		}
    	}
    	fputs($fp, implode("", $file));
    	fclose($fp);
    	$after = file_get_contents($resulttxt);
    	$sid = trim($sid);
    	$sid = str_replace("\r", "", $sid);
    	$sid = str_replace("\n", "", $sid);
    	$after .= "$sid;work\n";
    	file_put_contents($resulttxt, $after);
    	if($_GET["action"] == "y") {
    		$str = trim("$sid;work");
    		$edit  = trim("$sid;da"); 
    		$file = file($resulttxt);
    		if (is_array($file)) {
    			foreach($file as $key => $value) {
    				$file[$key] = str_replace($str, $edit, $value); 
    			}
    		}
    		$fp = fopen($resulttxt, "w"); 
    		fwrite($fp, implode("", $file)); 
    		fclose($fp);
    	} else if ($_GET["action"] == "n") {
    		$str = trim("$sid;work");
    		$edit = trim("$sid;net"); 
    		$file = file($resulttxt);
    		if (is_array($file)) {
    			foreach($file as $key => $value) {
    				$file[$key]= str_replace($str, $edit, $value); 
    			}
    		}
    		$fp = fopen($resulttxt, "w"); 
    		fwrite($fp, implode("", $file)); 
    		fclose($fp);
    	}
    }
    ?>


    Создал id.txt:
    1
    12
    123
    1234
    12345
    123456
    1234567


    Создал пустой файл result.txt.

    Итог:
    1. Делаю запрос к index.php (localhost/index.php?str=7&action=y)
    2. Проверяю файл id.txt:
    1
    12
    123
    1234
    12345
    123456

    2. Проверяю файл result.txt:
    1234567;da
    Ответ написан
    Комментировать
  • Как сделать прокрутку?

    @AdrianBlair
    Ответ написан
    Комментировать

Лучшие вопросы пользователя

Все вопросы (4)