Ideally I would like to add the span to everything but the first word but I can write my CSS code to work the other way.
You can do something like this:
<?php $string = "this is a test !"; $string = explode(" ", $string); echo array_shift($string) . ' <span>' . implode(" ", $string) . '</span>'; // returns: // this <span>is a test !</span>
array_shift removes the first element from the array and returns it. Here I used it to isolate the first word from the rest of the ‘exploded’ string.
This is easily adapted to wrap the first word with the
spans by just moving where in the output string you concatenate the
echo '<span>' . array_shift($string) . '</span> ' . implode(" ", $string);