How can I get the substring before the first space or dot?

Like

$string = "test.test"
//result = test

$string = "test doe"
//result = test

Sure I can use explode two times, but I am sure that's not the best solutions.

Edit
Report