proggR Posted July 12, 2008 Share Posted July 12, 2008 Is there anyway to break apart a string into groups? I have a string thats formatted DATE_COURSE_TITLE and i was wondering if there's a function that can grab any characters after the second underscore? And I don't need this to use but for knowledge sake, is there anyway to grab just between the two underscores as well? I'm guessing something like: $i = 0 if (character == "_"){ getcharacter; if (character == "_"){ $word = $buffer; } else{ $buffer[$i] = getcharacter; $i = $i+1; } would work but i was wondering if there was a function that would do it. even if i have to find the placement of each underscore and just feed start and end points into the function or something. althought i guess i could write that myself. anyway. i'm rambling because I'm in a hurry. Thanks in advance. Quote Link to comment Share on other sites More sharing options...
DarkWater Posted July 12, 2008 Share Posted July 12, 2008 $string = "DATE_COURSE_TITLE"; $new = explode("_", $string); $new[0] is "DATE", $new[1] is "COURSE, $new[2] is "TITLE". Quote Link to comment Share on other sites More sharing options...
mbeals Posted July 12, 2008 Share Posted July 12, 2008 Look up preg_match, Preg_match_all and preg_split for even more ways of hacking strings apart Quote Link to comment Share on other sites More sharing options...
DarkWater Posted July 12, 2008 Share Posted July 12, 2008 He just needs explode(). Quote Link to comment Share on other sites More sharing options...
mbeals Posted July 12, 2008 Share Posted July 12, 2008 He was asking for knowledge sake, so I thought I'd expand his knowledge by pointing him toward some more advanced functions. But yes, use explode if you can and save the regex for special cases. Quote Link to comment Share on other sites More sharing options...
DarkWater Posted July 12, 2008 Share Posted July 12, 2008 Oh. And if you ever need a SIMPLE replace, use str_replace instead of preg_replace or ereg_replace. And use strpos() instead of a regex to check to see if something is present, if possible. Quote Link to comment Share on other sites More sharing options...
proggR Posted July 12, 2008 Author Share Posted July 12, 2008 Thank you both. I just jotted them all down and I'll take a look more into them when I get a chance. Thanks again. 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.