(function($, undefined) {
"use strict";
// use this transport for "binary" data type
$.ajaxTransport("+binary", function(options, originalOptions, jqXHR) {
// check for conditions and support for blob / arraybuffer response type
if (window.FormData && ((options.dataType && (options.dataType == 'binary')) || (options.data && ((window.ArrayBuffer && options.data instanceof ArrayBuffer) || (window.Blob && options.data instanceof Blob))))) {
return {
// create new XMLHttpRequest
send: function(headers, callback) {
// setup all variables
var xhr = new XMLHttpRequest(),
url = options.url,
type = options.type,
async = options.async || true,
// blob or arraybuffer. Default is blob
dataType = options.responseType || "blob",
data = options.data || null,
username = options.username || null,
password = options.password || null;
xhr.addEventListener('load', function() {
var data = {};
data[options.dataType] = xhr.response;
// make callback and send data
callback(xhr.status, xhr.statusText, data, xhr.getAllResponseHeaders());
});
xhr.addEventListener('error', function() {
var data = {};
data[options.dataType] = xhr.response;
// make callback and send data
callback(xhr.status, xhr.statusText, data, xhr.getAllResponseHeaders());
});
xhr.open(type, url, async, username, password);
// setup custom headers
for (var i in headers) {
xhr.setRequestHeader(i, headers[i]);
}
xhr.responseType = dataType;
xhr.send(data);
},
abort: function() {}
};
}
});
})(window.jQuery);
$.ajax({
type: "POST",
url: "../report.php",
data: formData,
dataType: 'binary',
processData: false,
success: function (resp, status, xhr) {
var disposition = xhr.getResponseHeader('Content-Disposition');
var filename = disposition.substring(disposition.indexOf('filename=') + 'filename='.length).replace(/['"]/g, '');
var type = xhr.getResponseHeader('Content-Type');
var blob = new Blob([resp], {type: type});
var download_url = (window.URL || window.webkitURL).createObjectURL(blob);
var a = document.createElement("a");
a.href = download_url;
a.download = filename;
document.body.appendChild(a);
a.click();
},
error: function (xhr) {
...
}
});
$opts = [
'http' => [
'method' => 'GET',
'header' => implode("\r\n", ['Accept: *', 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) Chrome/76.0.3809.132 Edg/44.18362.267.0'])
]
];
$context = stream_context_create($opts);
echo file_get_contents('https://www.whatismybrowser.com/', false, $context);
$rand_frases = array_rand($frases, 1);
mt_srand(intdiv(time(), 1800));
$rand_frases = mt_rand(0, count($frases) - 1);
* 3 * * *
- это не каждые три часа, а 60 раз в сутки, каждую минуту с 03:00 до 03:59.0 */3 * * *
- вот так будет каждые три часа. echo $this->idSotrud->name[0];
echo mb_substr($this->idSotrud->name, 0, 1);
$text = '<p>Ехал <span>Грека</span> через <a href="#">реку</a></p> а это не изменится';
$doc = new DomDocument('1.0', 'utf-8');
$doc->loadXML('<?xml version="1.0" encoding="utf-8"?><body>' . $text . '</body>');
$xpath = new DomXPath($doc);
$elements = $xpath->query('//p//text()');
foreach ($elements as $tn) {
$tn->nodeValue = mb_strtoupper($tn->nodeValue);
}
echo mb_substr($doc->saveXML($doc->getElementsByTagName('body')->item(0)), 6, -7);
/* На выходе:
* <p>ЕХАЛ <span>ГРЕКА</span> ЧЕРЕЗ <a href="#">РЕКУ</a></p> а это не изменится
*/
$string = "title*=UTF-8''%c2%a3%20and%20%e2%82%ac%20rates";
list($name, $content) = explode('*=', $string);
list($enc, $lang, $raw) = explode("'", $content);
$final = mb_convert_encoding(urldecode($raw), 'utf-8' /* целевая кодировка */, $enc);