ale1981 Posted July 12, 2007 Share Posted July 12, 2007 Hi, Sorry if this is a really simple question but I have searched the php manual and cant seem to work out how to do it. I have a string like this; Full Name (Department) How can I split that string into seperate strings for Full Name and Department, so that everything before the () is the full name and everything between the () is the department? Thanks in advance. Quote Link to comment Share on other sites More sharing options...
tapos Posted July 12, 2007 Share Posted July 12, 2007 You can use preg_split() function. here u can find.. http://us.php.net/manual/en/function.preg-split.php -- Tapos Pal Quote Link to comment Share on other sites More sharing options...
ale1981 Posted July 12, 2007 Author Share Posted July 12, 2007 Could you explain what regular expression i would use to create the correct array? Quote Link to comment Share on other sites More sharing options...
effigy Posted July 12, 2007 Share Posted July 12, 2007 <pre> <?php $string = 'Full Name (Department)'; $pieces = preg_split('/[()]/', $string, -1, PREG_SPLIT_NO_EMPTY); print_r($pieces); ?> </pre> Quote Link to comment Share on other sites More sharing options...
ale1981 Posted July 12, 2007 Author Share Posted July 12, 2007 That works great, thanks effigy 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.