I am working on script to deal with strings, and I need it to take strings such as what you see below, and separate it out as seen below that. $string_A = "some-random-text-t9958302" $string_B = "unimportant-text-f100394" $string_C = "nothing-here-matters-at-all-m4954433" I am trying to pull the portion after the last - out of it, and separate it. $string_A[0] = "t" $string_A[1] = "9958302" $string_B[0] = "f" $string_B[1] = "100394" $string_C[0] = "m" $string_C[1] = "4954433" For some reason this last left me stumped... Any Ideas?
$string_A = "some-random-text-t9958302" $explode_array = explode('-',$string_A); $last_element = end($explode); $string_array_a[0] = substr($last_element,0); $string_array_a[1] = substr($last_element, 1); That should do it. I mean thats the basic logic to use - just massage it a bit to suite your needs
Another approach: preg_match('/-([a-z])(\d+)$/', $string_A, $matches); $array_shift($matches); $string_A = $matches; Code (markup):