dis Posted August 26, 2008 Share Posted August 26, 2008 Hello, I currently have: <?php router::register('about/:id="/^\d/"/:title'); ?> I need to split the string by '/', unless '/' is found inside the ="" section. So, I need a function to split the above into an array which should match (hence why explode will not work): Array( [0] = about [1] = :id="/^\d/"; [2] = :title ) I can do this via array loops and strpos functions, but that seems slow and stupid. I am wondering if this can be done via a preg_match, returning matches. Any help would be fantastic. Cheers, - dis. Quote Link to comment Share on other sites More sharing options...
redarrow Posted August 26, 2008 Share Posted August 26, 2008 try in_array function then.......... Quote Link to comment Share on other sites More sharing options...
joquius Posted August 26, 2008 Share Posted August 26, 2008 Uhh what does this mean: I need to split the string by '/', unless '/' is found inside the ="" section. and what do you want to get out of this: [1] = :id="/^\d/"; the string inside the double quotes? This kind of thing can be done really easily with preg_match I just need to know what you want to do. Quote Link to comment Share on other sites More sharing options...
dis Posted August 26, 2008 Author Share Posted August 26, 2008 Sorry, it is sort of confusing. All I need to get is an array. I am not worrying about anything inside the "" at the moment, just the process of splitting up the original string. Basically I need to split the string by /. However, if / is located inside the quotes ="", I don't want it to split. Some further examples: <?php router::register('about/:title'); Array( [0] = about [1] = :title ) router::register('about/:title="/"'); Array( [0] = about [1] = :title="/" ) router::register('about/:title/:id="/^\d/"); Array( [0] = about [1] = :title [2] = :id="/^\d/" ) ?> Those above are the results I am looking for. If you need further explaination, please let me know. Quote Link to comment Share on other sites More sharing options...
joquius Posted August 26, 2008 Share Posted August 26, 2008 Uhh preg_match_all ('/(:?.+?(?:=\".+?\")?)(?:\/|$)/s', $str, $matches); $str = 'about/:title="/"'; array(2) { [0]=> array(2) { [0]=> string(6) "about/" [1]=> string(10) ":title="/"" } [1]=> array(2) { [0]=> string(5) "about" [1]=> string(10) ":title="/"" } } Quote Link to comment Share on other sites More sharing options...
dis Posted August 26, 2008 Author Share Posted August 26, 2008 Thanks alot joquius. Much appreciated! 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.