function getFormData($method) {
// GET или POST: данные возвращаем как есть
if ($method === 'GET') return $_GET;
if ($method === 'POST') return $_POST;
// PUT, PATCH или DELETE
$data = array();
$exploded = explode('&', file_get_contents('php://input'));
foreach($exploded as $pair) {
$item = explode('=', $pair);
if (count($item) == 2) {
$data[urldecode($item[0])] = urldecode($item[1]);
}
}
return $data;
}
> echo hash('sha256', 'bla-bla-bla');
> e29256c37ac614866b41c51eb8bf013d2f0b208988a21016e0abf6e81fc99c58
<?
$input_arr = [
"/home/fol1/test.txt",
"/home/fol1/Browsers/test2.txt",
"/home/fol2/Browsers/test3.txt",
"/home/fol2/Browsers/ttre/test2.txt"
];
$out_arr = [];
foreach($input_arr as $item)
{
$folders = explode('/', $item);
$key = $folders[2];
if(!isset($out_arr[$key]) || !array_key_exists($item, $out_arr[$key])) // если еще не был такой путь
$out_arr[$key][] = $item;
}
print_r($out_arr);
?>
$html = <<<'HTML'
<article>
<p rel="#" src="#">aaaaaa</p>
<p href="#" bla="#" bla2="#">bbbbbb</p>
</article>
HTML;
$dom = new DOMDocument;
@$dom->loadHTML($html, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
$xpath = new DomXPath($dom);
$elements = $xpath->query('//article/*');
$allowedAttributes = ['src', 'href'];
foreach($elements as $element) {
for( $i = $element->attributes->length; --$i >= 0; ) {
if( ! in_array( $element->attributes->item($i)->name, $allowedAttributes ) ) {
$element->removeAttribute($element->attributes->item($i)->name);
}
}
}
echo $dom->saveHTML();
https://3v4l.org/UPrsr