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. Link to comment https://forums.phpfreaks.com/topic/59615-search-a-string-and-return-string-between-char/ 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 Link to comment https://forums.phpfreaks.com/topic/59615-search-a-string-and-return-string-between-char/#findComment-296245 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? Link to comment https://forums.phpfreaks.com/topic/59615-search-a-string-and-return-string-between-char/#findComment-296268 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> Link to comment https://forums.phpfreaks.com/topic/59615-search-a-string-and-return-string-between-char/#findComment-296311 Share on other sites More sharing options...
ale1981 Posted July 12, 2007 Author Share Posted July 12, 2007 That works great, thanks effigy Link to comment https://forums.phpfreaks.com/topic/59615-search-a-string-and-return-string-between-char/#findComment-296323 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.