Member Avatar for ___150

Hi,

Is it possible to convert the first letter after @ to uppercase using preg_replace? I tried;

preg_replace('/\@(\w+)/', 'ucfirst("$1")', $str)

But nothing changed when I sent it... 😞

Already like that... It worked, but I don't know how to add the @ before the name that will be converted.

$str = '@james';
echo preg_replace_callback('/\@(\w+)/', 'up', ucfirst ($str));

function up ($matches) {
  return ucfirst ($matches[1]);
}

Try this:

echo preg_replace('/@[\w+]/', '@' . ucfirst ($str[1]), $str);

or

echo preg_replace('/[@][\w+]/', $str[0] . ucfirst ($str[1]), $str);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.