mkosmosports Posted May 15, 2007 Share Posted May 15, 2007 Hey, Ive got the below strings: 100-500 3450-7890 Is there a function I can use to extract the strings before and after the "-"? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/51581-string-manipulation/ Share on other sites More sharing options...
boo_lolly Posted May 15, 2007 Share Posted May 15, 2007 explode() <?php $string1 = '100-500'; $string2 = '3450-7890'; $array1 = explode('-', $string1); $array2 = explode('-', $string2); ?> Quote Link to comment https://forums.phpfreaks.com/topic/51581-string-manipulation/#findComment-254037 Share on other sites More sharing options...
mkosmosports Posted May 16, 2007 Author Share Posted May 16, 2007 Thanks boo lolly. That works. Ive created another method though that doesnt require creating arrays (I need strings in the end anyways). Here it is using the below string: $string1 = '100-500'; $lowval = substr("$string1",0,strpos("$string1","-")); //Number before - $highval = substr(strstr("$string1","-"),1); //Number after - Quote Link to comment https://forums.phpfreaks.com/topic/51581-string-manipulation/#findComment-254043 Share on other sites More sharing options...
Jenk Posted May 16, 2007 Share Posted May 16, 2007 list($low, $high) = explode('-', $string); Quote Link to comment https://forums.phpfreaks.com/topic/51581-string-manipulation/#findComment-254045 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.