Nodral Posted January 11, 2012 Share Posted January 11, 2012 Hi All This may fall into regex, so my apologies if it does. I have a string from a prebuilt database, where it details the information responses to a radio button input. The issue I have, is that it is in the format "d>>>>>>North East|North West|South East|South West" I can't guarentee the first character is always a d and I don't know how many '>'s there are. Can someone help me remove these, then I can populate into an array using explode(). Quote Link to comment Share on other sites More sharing options...
Psycho Posted January 11, 2012 Share Posted January 11, 2012 If there will only be one character that precedes the > characters then this will work: $output = preg_replace("#^[^>]>+#", "", $input); If there can be more than one character, than this should work $output = preg_replace("#^[^>]+>+#", "", $input); Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted January 11, 2012 Share Posted January 11, 2012 I can't guarantee the first character is always a d Yes, but what can it be? Can it be missing. Can it be other letters? A number? Will it always be a single letter? Is it always at the start of a new line? Will there always be at least one > character and the > character won't ever appear in the part of the staring that you do want to keep? Will there ever be anything (spaces/tabs/numbers...) after the last > and the start of the string that you do want to keep? Does the part of the string that you do want to keep always start with an alpha (letter) character? 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.