I need to capitalize in my Rex Capture / matches, say that I want to capitalize the first letter after a hyphen, My Reggae will be something like this:
- (.)
And my replacement string should be something like this:
- In
preg_replace , I have something like this:
$ string = preg_replace ('/ - (.) / ',' - \ 1 ', $ string);
But this
Preg_replace (and I do not think it helps in changing the case in a backfirst) Suggestion: < P>
You can use it like this:
$ string = Preg_replace_callback ('# (? & Lt) ; = -) (.) # ', Create_function (' $ matches', 'return strtoupper ($ matches [1]);', $ string); Or, with an anonymous function (using PHP ver> gt; = 5.3.0):
$ string = preg_replace_callback (' # (? & Lt; = -) (.) # ', Function ($ matches) {return to stropper ($ matches [1]);}, $ string); Live demo:
No comments:
Post a Comment