Belgin Fish
Belgin Fish

Reputation: 19837

Split a string only on the first of its multiple delimiters to produce a 2-element array

How can I isolate the numbers and words in a string?

So I have something like this:

11111111-test-title

I want to have:

11111111

...in one string and:

test-title

...in another.

Upvotes: 0

Views: 206

Answers (2)

netcoder
netcoder

Reputation: 67715

You can use list and explode:

list($number, $text) = explode('-', $input, 2);

Or simply explode to get an array. The third argument tells it to separate it in a maximum of two parts, stopping after the first -.

Upvotes: 3

zerkms
zerkms

Reputation: 254944

$parts = explode('-', $string, 2);

Upvotes: 3

Related Questions