View Full Version : split string
02-25-2007, 09: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?
02-25-2007, 10:03 AM
$str = 'test-tester';
$strArray = explode('-',$str); // splits $str into an array: ['test']['tester']
return $strArray; // return the first item in the array
02-25-2007, 10:20 AM
string is teh same before and after the split
02-25-2007, 10: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, not $str.
Powered by vBulletin® Version 4.2.2 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.