$imagejpeg = imagecreatefromjpeg(__DIR__ . '/test.jpg');
$imagejpeg = imagecropauto($imagejpeg, IMG_CROP_THRESHOLD, 1, 16777215);
header('Content-Type: image/jpeg');
echo imagejpeg($imagejpeg);
<?php
$str = <<<EOT
<a aria-label="фотография" onclick="return showPhoto('-100714248_457263530', 'wall-100714248_195733', {"temp":{"x":"https:\/\/sun1.tattelecom-nbc.userapi.com\/8WCKHhWVE1k0ZOFPMjhSrMVIfwh6paa3fAu2Ew\/BLrYmamsJYw.jpg","y":"https:\/\/sun1.tattelecom-nbc.userapi.com\/IEPNRfOSuMSCWPzbLlvf1BAgo7iq47V_Ea5Sag\/ReADACWxqrc.jpg","z":"https:\/\/sun2.tattelecom-nbc.userapi.com\/P7QodnS3oEGJ9GNXBEd0vTopaGuv0Uw-1Gnnrg\/Q-ytzLXop9M.jpg","x_":["https:\/\/sun1.tattelecom-nbc.userapi.com\/8WCKHhWVE1k0ZOFPMjhSrMVIfwh6paa3fAu2Ew\/BLrYmamsJYw",359,604],"y_":["https:\/\/sun1.tattelecom-nbc.userapi.com\/IEPNRfOSuMSCWPzbLlvf1BAgo7iq47V_Ea5Sag\/ReADACWxqrc",480,807],"z_":["https:\/\/sun2.tattelecom-nbc.userapi.com\/P7QodnS3oEGJ9GNXBEd0vTopaGuv0Uw-1Gnnrg\/Q-ytzLXop9M",587,987],"base":""},"queue":1}, event)" style="width: 68px; height: 115px;background-image: url(https://sun1.tattelecom-nbc.userapi.com/GPHn0KGJ-tYVSZgVyGegulTCONVIiCM4J_8_QQ/TLNR1gH5bAE.jpg);" class="page_post_thumb_wrap image_cover page_post_thumb_last_column fl_l page_post_thumb_not_single" data-photo-id="-100714248_457263530"></a>
EOT;
if (preg_match('/return showPhoto\(.+, {(.+)}, .+\)/', $str, $output)) {
$linkData = json_decode('{' . $output[1] . '}', true);
print_r($linkData);
}
Array
(
[temp] => Array
(
[x] => https://sun1.tattelecom-nbc.userapi.com/8WCKHhWVE1k0ZOFPMjhSrMVIfwh6paa3fAu2Ew/BLrYmamsJYw.jpg
[y] => https://sun1.tattelecom-nbc.userapi.com/IEPNRfOSuMSCWPzbLlvf1BAgo7iq47V_Ea5Sag/ReADACWxqrc.jpg
[z] => https://sun2.tattelecom-nbc.userapi.com/P7QodnS3oEGJ9GNXBEd0vTopaGuv0Uw-1Gnnrg/Q-ytzLXop9M.jpg
[x_] => Array
(
[0] => https://sun1.tattelecom-nbc.userapi.com/8WCKHhWVE1k0ZOFPMjhSrMVIfwh6paa3fAu2Ew/BLrYmamsJYw
[1] => 359
[2] => 604
)
[y_] => Array
(
[0] => https://sun1.tattelecom-nbc.userapi.com/IEPNRfOSuMSCWPzbLlvf1BAgo7iq47V_Ea5Sag/ReADACWxqrc
[1] => 480
[2] => 807
)
[z_] => Array
(
[0] => https://sun2.tattelecom-nbc.userapi.com/P7QodnS3oEGJ9GNXBEd0vTopaGuv0Uw-1Gnnrg/Q-ytzLXop9M
[1] => 587
[2] => 987
)
[base] =>
)
[queue] => 1
)
function getProperties(array $haystack, string $needle): array
{
$result = [];
foreach ($haystack as $key => $item) {
if ($key === $needle) {
$result[] = $item;
} elseif (is_array($item)) {
$result = array_merge($result, getProperties($item, $needle));
}
}
return $result;
}
'products': <?= json_encode($products, JSON_UNESCAPED_UNICODE) ?>,
<?php
function prepareDataForDashboard(array $data, DateTimeInterface $minDate, DateTimeInterface $maxDate): array {
$dateInterval = new DateInterval('P1D');
$datePeriod = new DatePeriod($minDate, $dateInterval, $maxDate);
$result = [];
foreach ($datePeriod as $item) {
$date = $item->format('m-Y');
$result[$date] = [
'date' => $date,
'name' => null,
];
}
foreach ($data as $item) {
$date = DateTimeImmutable::createFromFormat('m-Y', $item['date']);
$date = $date->format('m-Y');
$result[$date] = $item;
}
return array_values($result);
}
$data = [
['date' => '06-2020', 'name' => 'Vanaya'],
['date' => '01-2020', 'name' => 'Petya'],
['date' => '04-2019', 'name' => 'Grizha'],
['date' => '11-2019', 'name' => 'Oleg'],
];
$minDate = new DateTimeImmutable('01.04.2019');
$maxDate = new DateTimeImmutable('01.06.2020');
$result = prepareDataForDashboard($data, $minDate, $maxDate);
print_r($result);
if (R::findOne('favorite', ' favorite = ? AND user_id = ?', [$bookName, $userId])) {
echo "такая книга уже есть";
}
SourceQuery::GOLDSOURCE
SourceQuery::SOURCE
$var1 = '9995КНМ';
$var2 = '9996КНМ';
function check(string $var1, string $var2): array
{
$matches = [];
$length = mb_strlen($var2);
for ($i = 0; $i < $length; $i++) {
for ($j = 1; $j < $length - $i + 1; $j++) {
$substr = mb_substr($var2, $i, $j);
$substrLength = mb_strlen($substr);
$substrCount = mb_substr_count($var1, $substr);
if ($substrCount) {
$matches[$substr] = [
'substr' => $substr,
'length' => $substrLength,
'count' => $substrCount,
];
}
}
}
return array_values($matches);
}
$matches = check($var1, $var2);
Array
(
[0] => Array
(
[substr] => 9
[length] => 1
[count] => 3
)
[1] => Array
(
[substr] => 99
[length] => 2
[count] => 1
)
[2] => Array
(
[substr] => 999
[length] => 3
[count] => 1
)
[3] => Array
(
[substr] => К
[length] => 1
[count] => 1
)
[4] => Array
(
[substr] => КН
[length] => 2
[count] => 1
)
[5] => Array
(
[substr] => КНМ
[length] => 3
[count] => 1
)
[6] => Array
(
[substr] => Н
[length] => 1
[count] => 1
)
[7] => Array
(
[substr] => НМ
[length] => 2
[count] => 1
)
[8] => Array
(
[substr] => М
[length] => 1
[count] => 1
)
)
<?php
$numbers1 = [-5, 10, 0, 1, 2, 3, 6, 7, 8, 9, 12, 13, 14, 15];
$numbers2 = [10, 0, 1, 2, 3, 6, 7, 8, 9, 12, 13, 14, 15];
function intervals(array $numbers): array
{
$numbers = array_unique($numbers);
sort($numbers);
$length = count($numbers);
$intervals = [];
$start = null;
$end = null;
for ($i = 0; $i < $length; $i++) {
$currentItem = $numbers[$i];
$nextItem = $numbers[$i + 1] ?? null;
if ($currentItem + 1 === $nextItem) {
if ($start === null) {
$start = $currentItem;
}
$end = $nextItem;
continue;
}
if ($start === null || $end === null) {
continue;
}
$intervals[] = [
'start' => $start,
'end' => $end,
];
$start = $nextItem;
}
return $intervals;
}
print_r(intervals($numbers1));
print_r(intervals($numbers2));