Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Isolate leading string before one of two delimiting characters

Tags:

substring

php

Is there any nice way to split an string on a space or a 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 ;)

like image 485
opHASnoNAME Avatar asked Jun 30 '09 11:06

opHASnoNAME


1 Answers

If you want to split on several different chars, take a look at preg_split

//split string on space or period:
$split=preg_split('/[ \.]/', $string);
like image 128
Paul Dixon Avatar answered Nov 15 '22 21:11

Paul Dixon