Return the portion of a string before the first occurrence of a character in PHP [duplicate]

In PHP, what is the simplest way to return the portion of a string before the first occurrence of a specific character?

For example, if I have a string...

"The quick brown foxed jumped over the etc etc."

...and I am filtering for a space character (" "), the function would return "The".


Solution 1:

For googlers: strtok is better for that:

echo strtok("The quick brown fox", ' ');

Solution 2:

You could do this:

$string = 'The quick brown fox jumped over the lazy dog';
$substring = substr($string, 0, strpos($string, ' '));

But I like this better:

list($firstWord) = explode(' ', $string);