Matrixkid Posted May 22, 2009 Share Posted May 22, 2009 Hi there, I have a string that looks like this; 2-Name,3-Name,4-Name,5-Name,6-Name,7-name Im trying to preg_split the string into an array so that all im left with is name, I can remove the comma no problem once its split up I have tried the following: $array_name = preg_split("/[0-9][-]/",$names); $array_name = preg_split("/[0-9-]/",$names); $array_name = preg_split("/[0-9]-]/",$names); Thanks for your help! Cheers MK Quote Link to comment https://forums.phpfreaks.com/topic/159303-solved-regex-for/ Share on other sites More sharing options...
Maq Posted May 22, 2009 Share Posted May 22, 2009 This just gets "name", and takes the comma out as well. If you want to take the comma out yourself then remove ',?'. $names = "2-Name,3-Name,4-Name,5-Name,6-Name,7-name"; $array_name = preg_split("/,?\d-/",$names); print_r($array_name); ?> Quote Link to comment https://forums.phpfreaks.com/topic/159303-solved-regex-for/#findComment-840171 Share on other sites More sharing options...
Matrixkid Posted May 22, 2009 Author Share Posted May 22, 2009 thanks Quote Link to comment https://forums.phpfreaks.com/topic/159303-solved-regex-for/#findComment-840173 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.