Reputation: 13404
How to remove the first word away in Smarty from a string, that looks like:
$variable = "Word Quick brown fox";
And make it look like this afterwards on the output:
$variable = "Quick brown fox";
Is there a way to do this without modifiers? I know you can make custom modifier and then use $variable|customModifier
and get what you want but I thought maybe there is already inbuilt solution for that?
Upvotes: 0
Views: 4128
Reputation: 36937
Explode the original string into an array via the space between the words, then slice out the chosen index key. Then implode the array back to a string.
<?php
$variable = "Word Quick brown fox";
$str = explode(' ', $variable);
$str = array_slice($str, 1);
$str = implode(' ', $str);
echo $str;
?>
Upvotes: 3
Reputation: 59699
As Tyler points out, this should be done in your business logic, like so:
explode()
on a space to create an array of wordsarray_shift()
(corresponding to the first word in the sentence)implode()
Here is an example:
$words = explode( ' ', $variable);
array_shift( $words);
$variable = implode( ' ', $words);
Upvotes: 8