Hood15 Posted May 13, 2008 Share Posted May 13, 2008 Hello, I've already done the task by using explode and stuff. However, I think that regex would be faster and the right thing to use. Could anyone show me how this can be done with regex? I'm attempting to change l:blocks/nav.tpl;r:blocks/your_account.tpl,blocks/whos_online.tpl in to Array ( [l] => Array ( [0] => blocks/nav.tpl ) [r] => Array ( [0] => blocks/your_account.tpl [1] => blocks/whos_online.tpl ) ) The code I used to get that with explode was $_blocks = explode(';', $main_class->modules->info['blocks']); for ($i = 0; $i < count($_blocks); $i++) { $side = explode(':', $_blocks[$i]); $files = explode(',', $side[1]); for ($file_i = 0; $file_i < count($files); $file_i++) { $blocks["{$side[0]}"][] = $files["{$file_i}"]; } } print_r($blocks); Quote Link to comment Share on other sites More sharing options...
effigy Posted May 13, 2008 Share Posted May 13, 2008 Not a vast improvement, but regex nonetheless: <pre> <?php $str = 'l:blocks/nav.tpl;r:blocks/your_account.tpl,blocks/whos_online.tpl'; preg_match_all('/([lr])[^;]+)/', $str, $matches); $sides = count($matches[0]); for ($i = 0; $i < $sides; $i++) { $blocks[$matches[1][$i]] = explode(',', $matches[2][$i]); } print_r($blocks); ?> </pre> Quote Link to comment 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.