How do you use PHP’s preg_match to replace:
- White space, and
- Comma, and
- Combination of white space AND comma
For example, consider the following string:
apple orange,strawberry, coconut
Note that:
- Only white space is used between “apple” and “orange”
- Only comma is used between “orange” and “strawberry”
- Both white space and comma is used between “strawberry” and “coconut”
How do I use preg_match to replace all occurences of the listed elements above with the word YES, that results in the following string
appleYESorangeYESstrawberryYEScoconut
Thanks in advance!
1 Answer