<?php
const URLS = [
"http://site.com/",
"http://site.com/save",
"http://site.com/save/results",
"http://site.com/save/results/path",
"http://site.com/path/save/results",
"http://site.com/save/path",
"http://site.com/path/results",
"http://site.com/Crawler4",
"http://site.com/Crawler",
];
$seen = [];
$siteStructure = [];
foreach (URLS as $url)
{
['scheme' => $scheme, 'host' => $host, 'path' => $path] = parse_url($url);
$realm = $scheme . '://' . $host;
$siteStructure[$realm] ??= [];
$current = &$siteStructure[$realm];
$pathEls = preg_split('/[^a-zA-Z0-9]+/', $path, 0, PREG_SPLIT_NO_EMPTY);
foreach ($pathEls as $el)
{
$current[$el] ??= [];
$current = &$current[$el];
}
unset($current);
}
var_dump($siteStructure);
- Output for 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
- array(1) {
["http://site.com"]=>
array(4) {
["save"]=>
array(2) {
["results"]=>
array(1) {
["path"]=>
array(0) {
}
}
["path"]=>
array(0) {
}
}
["path"]=>
array(2) {
["save"]=>
array(1) {
["results"]=>
array(0) {
}
}
["results"]=>
array(0) {
}
}
["Crawler4"]=>
array(0) {
}
["Crawler"]=>
array(0) {
}
}
}
- Output for 8.3.5
- Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
array(1) {
["http://site.com"]=>
array(4) {
["save"]=>
array(2) {
["results"]=>
array(1) {
["path"]=>
array(0) {
}
}
["path"]=>
array(0) {
}
}
["path"]=>
array(2) {
["save"]=>
array(1) {
["results"]=>
array(0) {
}
}
["results"]=>
array(0) {
}
}
["Crawler4"]=>
array(0) {
}
["Crawler"]=>
array(0) {
}
}
}
- Output for 7.3.0 - 7.3.33
- Parse error: syntax error, unexpected '=' in /in/f7Lj8 on line 23
Process exited with code 255.
preferences:
152.35 ms | 401 KiB | 150 Q