youdontmeanmuch Posted July 6, 2008 Share Posted July 6, 2008 Big Picture I'm in the middle of designing a CMS right now, I've got everything down and a lot of the classes built and general framework working. I'm actually down to the CMS architecture right now. I know how I want it, and how it has to be... but I'm missing one piece. This piece, a very important one! 8O Smaller Picture I have all non-existing pages re-directing to say request_handler.php?q=$1 with $1 being the requested page maybe /help/me/ The handler will check the 'content' table for the requested location. No problem there. The 'content' table contains a field called 'location' in order to generate my site map array I want to loop through the 'location's and explode the /'s to create the associative array I'm looking for. I'm working on designing site map array to create menu's/navigation etc... I've already got them working off of this associative array that i wrote up. Me Rambling If its possible its not easy and that's probably why i haven't seen this done before. I think if this can be tackled it will be a real important and smart part of the architecture of the CMS. I've tried a couple of different aproaches but didn't get far at all. I've spent most of my time scratching my head trying to figure out where to start. Obviously I'm going to have to use something like: foreach($link as $blah){ $something[] = explode('/',$blah); } but that gives me a non associative array. I put a array_flip on that and i got the array keys all good... they just weren't multidimensional? or below each other. I'm completely lost... The Code Example The _contents isn't important... the important and hard part to figure out (for me) is how to simply convert <?php // Quick Example $string = "this/is/my/example/"; // INTO $example['this']['is']['example'] ?> <?php // LONNG EXAMPLE // This is what I have. $link[] = "features/silly/text/facts"; $link[] = "features/silly/text/facts/cats"; $link[] = "features/silly/text/facts/dogs"; $link[] = "features/silly/text/jokes"; $link[] = "features/silly/text/jokes/cats"; $link[] = "features/silly/text/jokes/dogs"; $link[] = "features/silly/pictures/pets"; $link[] = "features/silly/pictures/pets/cats"; $link[] = "features/silly/pictures/pets/dogs"; $link[] = "features/silly/video/pets"; $link[] = "features/silly/video/pets/cats"; $link[] = "features/silly/video/pets/dogs"; $link[] = "features/silly/me"; $link[] = "features/silly/you"; $link[] = "features/serious/text/facts"; $link[] = "features/serious/text/facts/cats"; $link[] = "features/serious/text/facts/dogs"; $link[] = "features/serious/text/poems"; $link[] = "features/serious/text/poems/cats"; $link[] = "features/serious/text/poems/dogs"; $link[] = "features/serious/pictures/pets"; $link[] = "features/serious/pictures/pets/cats"; $link[] = "features/serious/pictures/pets/dogs"; $link[] = "features/serious/video/pets"; $link[] = "features/serious/video/pets/cats"; $link[] = "features/serious/video/pets/dogs"; $link[] = "features/serious/me"; $link[] = "features/serious/you"; $link[] = "help/me"; $link[] = "help/me/please"; $link[] = "help/me/please/seriously"; // This is what I want... // Some how I want to end up with this resulting associative array. $assoc['features']['silly']['text']['facts']['_contents'] = ""; $assoc['features']['silly']['text']['facts']['cats'] = ""; $assoc['features']['silly']['text']['facts']['dogs'] = ""; $assoc['features']['silly']['text']['jokes']['_contents'] = ""; $assoc['features']['silly']['text']['jokes']['cats'] = ""; $assoc['features']['silly']['text']['jokes']['dogs'] = ""; $assoc['features']['silly']['pictures']['pets']['_contents'] = ""; $assoc['features']['silly']['pictures']['pets']['cats'] = ""; $assoc['features']['silly']['pictures']['pets']['dogs'] = ""; $assoc['features']['silly']['video']['pets']['_contents'] = ""; $assoc['features']['silly']['video']['pets']['cats'] = ""; $assoc['features']['silly']['video']['pets']['dogs'] = ""; $assoc['features']['silly']['me']['_contents'] = ""; $assoc['features']['silly']['you']['_contents'] = ""; $assoc['features']['serious']['text']['facts']['_contents'] = ""; $assoc['features']['serious']['text']['facts']['cats'] = ""; $assoc['features']['serious']['text']['facts']['dogs'] = ""; $assoc['features']['serious']['text']['jokes']['_contents'] = ""; $assoc['features']['serious']['text']['jokes']['cats'] = ""; $assoc['features']['serious']['text']['jokes']['dogs'] = ""; $assoc['features']['serious']['pictures']['pets']['_contents'] = ""; $assoc['features']['serious']['pictures']['pets']['cats'] = ""; $assoc['features']['serious']['pictures']['pets']['dogs'] = ""; $assoc['features']['serious']['video']['pets']['_contents'] = ""; $assoc['features']['serious']['video']['pets']['cats'] = ""; $assoc['features']['serious']['video']['pets']['dogs'] = ""; $assoc['features']['serious']['me']['_contents'] = ""; $assoc['features']['serious']['you']['_contents'] = ""; $assoc['help']['me']['_contents'] = ""; $assoc['help']['me']['please']['_contents'] = ""; $assoc['help']['me']['please']['seriously'] = ""; ?> Quote Link to comment https://forums.phpfreaks.com/topic/113435-solved-converting-thisexample-to-examplethisexample/ Share on other sites More sharing options...
maexus Posted July 6, 2008 Share Posted July 6, 2008 This may help, I had a similar issue. http://www.phpfreaks.com/forums/index.php/topic,201355.0.html Quote Link to comment https://forums.phpfreaks.com/topic/113435-solved-converting-thisexample-to-examplethisexample/#findComment-582883 Share on other sites More sharing options...
wildteen88 Posted July 6, 2008 Share Posted July 6, 2008 The following does what you want: <?php $link[] = "features/silly/text/facts"; $link[] = "features/silly/text/facts/cats"; $link[] = "features/silly/text/facts/dogs"; $link[] = "features/silly/text/facts/_contents"; $link[] = "features/silly/text/facts/cats"; $link[] = "features/silly/text/facts/dogs"; $link[] = "features/silly/text/jokes/_contents"; $link[] = "features/silly/text/jokes/cats"; $link[] = "features/silly/text/jokes/dogs"; $assoc = array(); foreach($link as $s_link) { $keys = explode('/', $s_link); eval('$assoc[\'' . implode('\'][\'', $keys) . '\'] = "";'); } echo '<pre>' . print_r($assoc, true) . '</pre>'; ?> How is the $assoc associative array going to be used latter on? Quote Link to comment https://forums.phpfreaks.com/topic/113435-solved-converting-thisexample-to-examplethisexample/#findComment-582884 Share on other sites More sharing options...
youdontmeanmuch Posted July 6, 2008 Author Share Posted July 6, 2008 Thank you very much! I was trying to do an eval on it before but i couldn't get the syntax (or my head) right. It was a very late night last night Anyhow I want to thank you very much for helping me out! You have no idea how happy and thankful I am! I'm going to try and stick around in these forums and try and post more... hopefully more answers than questions here. I feel like I need to give back Quote Link to comment https://forums.phpfreaks.com/topic/113435-solved-converting-thisexample-to-examplethisexample/#findComment-583162 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.