➜ /tmp ll foo.bar
-rw-rw-r-- 1 miraage miraage 87 Nov 25 17:47 foo.bar
➜ /tmp php -a
Interactive mode enabled
php > $size = filesize('foo.bar');
php > var_dump($size);
int(87)
php > $f = fopen('foo.bar', 'a+b');
php > ftruncate($f, $size - 1);
php > fclose($f);
php >
➜ /tmp ll foo.bar
-rw-rw-r-- 1 miraage miraage 86 Nov 25 17:48 foo.bar
Notice: unrecognized option - colour
{"code":200,"id":535829352}
/**
* Find JSON in string
*
* @param string $string Input string
* @return array
*/
function findJson($string)
{
$re = '~\{(?:[^{}]|(?R))*\}~';
if (preg_match($re, $string, $m)) {
$result = json_decode($m[0], true);
} else {
$result = ['error' => 'invalid_json'];
}
return $result;
}
// file1.php
$config = require_once '/path/to/file2.php';
echo $config['foo']; // bar
// file2.php
return [
'foo' => 'bar',
'bar' => 'baz',
];
preg_replace('~\xb1~u', '', $string);
$stmt->bindParam(':id', $id, PDO::PARAM_INT); // PDO::PARAM_STR по-умолчанию
$response = $client->request('PUT', '/put', ['json' => ['foo' => 'bar']]);
$input = [
[
'title' => 'Чтение',
'value' => 'да',
],
[
'title' => 'Тип',
'value' => 'общий',
],
[
'title' => 'Чтение',
'value' => 'нет',
],
[
'title' => 'Тип',
'value' => 'общий',
],
];
function get_unique_titles(array $input)
{
$tmp = [];
$result = [];
foreach ($input as $row) {
$tmp[$row['title']][] = $row['value'];
}
foreach ($tmp as $title => $values) {
if ($values == array_unique($values)) {
$result[] = $title;
}
}
return $result;
}
var_dump(get_unique_titles($input));
array(1) {
[0] =>
string(12) "Чтение"
}
containerWrap = document.getElementById("container");
var jQueryMinJs = document.createElement("script");
jQueryMinJs.onload = loadOtherScripts;
jQueryMinJs.src = "http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js";
containerWrap.appendChild(jQueryMinJs);
function loadOtherScripts() {
$.getScript('js/script__.js', function () {
console.log('script__.js loaded');
});
}