View Full Version : split string

02-25-2007, 10:46 AM
how can i split a string based on a -

i have a string as follows

I want to return just test -- how can i do this?

Bill Posters
02-25-2007, 11:03 AM

$str = 'test-tester';

$strArray = explode('-',$str); // splits $str into an array: ['test']['tester']

return $strArray[0]; // return the first item in the array

02-25-2007, 11:20 AM
not working

any idea?

string is teh same before and after the split

Bill Posters
02-25-2007, 11:35 AM
You said you wanted to return the first part of the string (split around -).
The above code shows that you need to return $strArray[0], not $str.