Jump to content

Help with trimming


Nodral

Recommended Posts

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().

 

 

Link to comment
https://forums.phpfreaks.com/topic/254804-help-with-trimming/
Share on other sites

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);

Link to comment
https://forums.phpfreaks.com/topic/254804-help-with-trimming/#findComment-1306501
Share on other sites

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?

Link to comment
https://forums.phpfreaks.com/topic/254804-help-with-trimming/#findComment-1306503
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.