Hello all, I try to accomplish the following.
I have a string like: “volkswage n-golf-gti” **
And I want it to change the string into:
“Volkswage n Golf GTI” (last part completely uppercase)
But I have some difficulties understanding preg_replace.
Right now I have the following code:
Without line 4 enabled, the result of the echo $string2 is:
Volkswagen Golf Gti (is wrong, last part is not completely uppercase)
With line 4 enabled, the last part of the $string is removed
so echo $string2 gives me :
Volkswagen Golf
How can I change the code so it select the last part of $string2 and makes that part uppercase? So the result of echo $string2; will be:
Volkswagen Golf GTI
** $string can be anything, not only volkswagen-golf-gti
I have a string like: “volkswage n-golf-gti” **
And I want it to change the string into:
“Volkswage n Golf GTI” (last part completely uppercase)
But I have some difficulties understanding preg_replace.
Right now I have the following code:
Code:
<?php $string = 'volkswagen-golf-gti'; $string2 = ucwords(str_replace('-', ' ', $string)); $string2 = preg_replace("/\s+\S+$/e", "strtoupper('\\1')", $string2); echo $string2; ?>
Volkswagen Golf Gti (is wrong, last part is not completely uppercase)
With line 4 enabled, the last part of the $string is removed
so echo $string2 gives me :
Volkswagen Golf
How can I change the code so it select the last part of $string2 and makes that part uppercase? So the result of echo $string2; will be:
Volkswagen Golf GTI
** $string can be anything, not only volkswagen-golf-gti
Comment