I need to split a string into two using a delimiter character. All I have to do is use the explode() function... I know.
But here is what I'm trying to do: I need to split a string using a delimiter but if the delimiter is enclosed in quotes it should be ignored.
Let's say my delimiter is a hyphen (-) and I need to split the following string:
The ‘big-yellow’ house-is near the lake
The first hyphen must be ignored because it is in quotes, therefore I would end up with two strings like these:
1. The ‘big-yellow’ house
2. is near the lake
And it also should be able to detect escaped quotes.
E.g.: He doesn\’t like it because-he isn\’t from here.
In this case the hyphen is not within quotes therefore the string should be split.
Any thoughts?