How can I split a string at the first occurrence of "-" (minus sign) into two $vars with PHP?

Viewed 42050

How can I split a string at the first occurrence of - (minus sign) into two $vars with PHP?

I have found how to split on every "-" but, not only on the first occurrence.

example:

this - is - line - of whatever - is - relevant
$var1 = this
$var2 = is - line - of whatever - is - relevant

Note, also stripped the first "-" .

Thanks in advance for the help!

4 Answers

You can use strtok function:

$first = strtok($string, '-');
Related