Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.