Closed Thread Icon

Topic awaiting preservation: site maps - regular expressions - counting slashes (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=12736" title="Pages that link to Topic awaiting preservation: site maps - regular expressions - counting slashes (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: site maps - regular expressions - counting slashes <span class="small">(Page 1 of 1)</span>\

 
smonkey
Paranoid (IV) Inmate

From: Northumberland, England
Insane since: Apr 2003

posted posted 05-14-2003 01:19

how can I divide/sort a php array in to multiple new arrays? there are some conditions to this so I will explain my situation:

I have a php script that recursively loops through all my website directories and gets all the htm/html/php files from them and put's them into an array as an absolute path. I would like to turn this array into some kind of file tree or easy to understand sitemap. I figure the array entries would need to be divided and sorted into a range of nested arrays or something and the sitemap made from that.
*My current locally tested array looks like :

[0] => c:\phpdev\www\ckg\splash.htm
[1] => c:\phpdev\www\ckg\index.htm
[2] => c:\phpdev\www\ckg\ckg\index.htm
[3] => c:\phpdev\www\ckg\ckg\thanks\index.htm
[4] => c:\phpdev\www\ckg\ckg\copyright\index.htm
[5] => c:\phpdev\www\ckg\ckg\contact\index.htm
[6] => c:\phpdev\www\ckg\ckg\about\index.htm
[7] => c:\phpdev\www\ckg\galleries\index.htm
[8] => c:\phpdev\www\ckg\galleries\submit\index.htm
[9] => c:\phpdev\www\ckg\galleries\artistlist\index.htm
[10] => c:\phpdev\www\ckg\galleries\photography\index.htm
[11] => c:\phpdev\www\ckg\galleries\media\index.htm
[12] => c:\phpdev\www\ckg\galleries\film\index.htm
[13] => c:\phpdev\www\ckg\galleries\art\index.htm
[14] => c:\phpdev\www\ckg\galleries\illustration\index.htm
[15] => c:\phpdev\www\ckg\galleries\illustration\thomas_meldgaard\index.htm
[16] => c:\phpdev\www\ckg\personal\jon\index.htm
[17] => c:\phpdev\www\ckg\personal\jay\index.htm
[18] => c:\phpdev\www\ckg\features\index.htm
[19] => c:\phpdev\www\ckg\features\hosting\index.htm
[20] => c:\phpdev\www\ckg\features\downloads\index.htm
[21] => c:\phpdev\www\ckg\features\links\index.htm
[22] => c:\phpdev\www\ckg\features\guestbook\index.htm
[23] => c:\phpdev\www\ckg\features\experiments\index.htm
[24] => c:\phpdev\www\ckg\features\experiments\text\text.htm
[25] => c:\phpdev\www\ckg\features\experiments\imgwall\imgwall1.htm
[26] => c:\phpdev\www\ckg\features\experiments\imgwall\imgwall2.htm
[27] => c:\phpdev\www\ckg\filelist.php
[28] => c:\phpdev\www\ckg\getfiles.php

Alternatively rather than make one array and then break it up into sub arrays is there a way that the following script can be made to put data into the nested arrays directly (each time it reads a sub directory in a directory create a new sub array etc.)? I basically want to run this script via a cron job every few days and create a seperate html sitemap file that is clear and understandable.<BLOCKQUOTE><FONT face="Verdana, Arial">code:</font><HR><pre><?php
$root_path = ".";
function parseDir($path)
{
if (!($dir_handler = opendir($path))) {
die("Can't opendir() path '". $path ."'");
}
$files = array();
while (($file = readdir($dir_handler)) !== false) {
$temp_path = realpath($path."/".$file);
if ($file != "." && $file != "..") {
if (is_dir($temp_path)) {
$files = array_merge($files, parseDir($temp_path));
} elseif (is_file($temp_path)) {
$pathInfo = pathinfo($temp_path);
if (preg_match("/(html?

Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 05-14-2003 10:17

again, without reading all of your posts,
you can easily nest arrays.

just say
$shu = array(array(1,2),array(3,4))
then you can do things like
$shu[0][1] = 5;
or even $shu[0][] = 6;

avidal
Bipolar (III) Inmate

From: austin, tx, usa
Insane since: Nov 2000

posted posted 05-24-2003 22:20

You can use variable variables also, I suppose.

[code]

$dir = "/test/";

$dir = str_replace("/","",$dir);

$$dir[0] = "index.php";

echo $test[0]; //outputs "index.php" <--- Not tested, but I think that's how variable variables work.

« BackwardsOnwards »

Show Forum Drop Down Menu