One way is to blow up a line in words using explode or preg_split (depending on the complexity of word separators: are they always the same space?)
For instance:
$string = "R 124 This is my message"; $words = explode(' ', $string); var_dump($words);
You will get an array like this:
array 0 => string 'R' (length=1) 1 => string '124' (length=3) 2 => string 'This' (length=4) 3 => string 'is' (length=2) 4 => string 'my' (length=2) 5 => string 'message' (length=7)
Then, array_slice , you save only the words you need (not the first two):
$to_keep = array_slice($words, 2); var_dump($to_keep);
What gives:
array 0 => string 'This' (length=4) 1 => string 'is' (length=2) 2 => string 'my' (length=2) 3 => string 'message' (length=7)
And finally, you add the fragments:
$final_string = implode(' ', $to_keep); var_dump($final_string);
What gives...
string 'This is my message' (length=18)
And, if necessary, this allows you to do a couple of manipulations on words before attaching them back together :-) Actually, this is the reason you can choose a solution that is a little longer using only explode and / or preg_split ^ ^
source share