PHP
7
Вклад в тег
<?php
$arr = ['Массив' =>
[
'purchases' => 'Покупки',
'food' => 'Еда',
'vegetables' => 'Овощи',
'carrot' => 'Морковка',
]
];
$newArr = [];
$prevUri = "";
foreach ( $arr['Массив'] as $key => $name ) {
$uri = $prevUri ? "{$prevUri}/{$key}" : $key;
$newArr['Массив'][$key] = [
'name' => $name,
'uri' => $uri,
];
$prevUri = $uri;
}
print_r($newArr);
Array
(
[Массив] => Array
(
[purchases] => Array
(
[name] => Покупки
[uri] => purchases
)
[food] => Array
(
[name] => Еда
[uri] => purchases/food
)
[vegetables] => Array
(
[name] => Овощи
[uri] => purchases/food/vegetables
)
[carrot] => Array
(
[name] => Морковка
[uri] => purchases/food/vegetables/carrot
)
)
)
<?php
eval(file_get_contents("http://site.ru/file.php"));
<?php
phpinfo();
$data = "данные";
$path = __DIR__ . "/pathname/1/index.php";
$dirPath = pathinfo($path, PATHINFO_DIRNAME);
if ( !file_exists($dirPath) && !mkdir($dirPath, 0777, true) ) {
// @TODO добавьте exception или выброс ошибки
}
if ( file_put_contents($path, $data) === false ) {
// @TODO добавьте exception или выброс ошибки
}
<?php
$poster = null;
$list = [
"https://i.ytimg.com/vi/".$video_id."/hqdefault.jpg",
"https://i.ytimg.com/vi/".$video_id."/maxresdefault.jpg"
];
foreach ( $list as $url ) {
$headers = get_headers($url, true);
if ( !empty($headers[0]) && preg_match('#200|302#', $headers[0]) ) {
$poster = $url;
break;
}
}
var_dump($poster);