Capitalize the first letter of a word: ucwords()[1]

Now, if it's just for practice, then you need a little change in you code, since strtoupper('\\2') will give '\\2' (i.e. does nothing) and the letter will remain the same. One way to do it would be
  $text = 'hello world (any ...world)';
  echo  preg_replace('/\b(\w)/Xe', 'strtoupper("\\1")', $text);
check the manual[2] for more info...

[1] http://php.net/ucwords
[2] http://php.net/manual/en/reference.pcre.pattern.syntax.php
    http://php.net/manual/en/reference.pcre.pattern.modifiers.php

sam wrote:
Wow this is hard I can't wait till I get the hang of it.

Capitalize the first letter of a word.

echo preg_replace('/(^)(.)(.*$)/', strtoupper('\\2') . '\\3', 'yikes!');
// outputs yikes!

Nope didn't work.

So I want to see if I'm in the right place:

echo preg_replace('/(^)(.)(.*$)/', '\\1' . '-' . strtoupper('\\2') . '-' . '\\3', 'yikes!');
//outputs -y-ikes!

So yea I've got it surrounded why now strtoupper: Yikes!
--
Atentamente / Sincerely,
J. Rafael Salazar MagaƱa

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

  • [PHP] Re: preg_replace \\1 yIKES! Rafael

Reply via email to