1

This is the code:

$arr=explode(", ",$this->maList);

maList returns the entered mails:

"[email protected], [email protected]"

However, I want it to know whether I've used space after the comma or no space. Because if I enter this:

"[email protected],[email protected]"

Then it becomes a single array element.

What can I do in this situation?

2 Answers 2

4

Just going to put another answer up, for those cases where there are spaces in the strings that you wish to keep. Mapping the trim function to the array items will remove any extra whitespace from the beginning or end, but not the middle.

$arr = explode(",", $this->maList);
$arr = array_map("trim", $arr);

This could be useful if you had:

"Test Name <[email protected]>"
Sign up to request clarification or add additional context in comments.

Comments

2

Well, I thought of the answer as I was writing the question, pretty easy actually. Since I'm grabbing emails, so forget the white spaces, so I just cut it off while casting the array.

$arr=explode(",",str_replace(' ', '', $this->maList));

1 Comment

simply use trim, it's far less cumbersome than str_replace: $arr=explode(",", trim($this->maList));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.