...

View Full Version : split string



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

i have a string as follows
test-tester

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

Bill Posters
02-25-2007, 11:03 AM
e.g.

$str = 'test-tester';

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

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

esthera
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum