I am using a self generated navigation using php. I need to wrap the first and second word in separate div classes. e.g.
<li> <span>First</span> <span class="word">Second</span> Word </li>
At the moment i can wrap the first word in a span class using
$name = preg_replace('/(?<=\>)\b(\w*)\b|^\w*\b/', '<span>$0</span>', $ni->name);
Does anyone know how I can alter this to wrap the first two words?
I don't know if I understood you well, but I think you need this:
or
You could split the words up in an array and replace the indexes you need.