Reputation: 5870
I have a string which can be one of the following:
$code = "123456 - US";
$code = "12-3456 - US";
$code = "WD123 - US";
$code = "A0-12 - US";
$code = "123456 - Poland";
How can I find out the first part (like 123456
or A0-12
) and the last part (like-US
or Poland
)?
Upvotes: 2
Views: 96
Reputation: 2262
you could use explode to split it into two parts.
$split = explode(" - ",$code);
That will give you an array with two elements: "123456" and "US"
Upvotes: 7