Re: preg_replace \\1 yIKES!

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



	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



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux