XHTML.net

Technology talks by Loïc d’Anterroches

News, articles, PHP, scripts, XHTML/CSS, …

  1. Home
  2. News

mb_ucwords en PHP

The 2007-11-01 at 09:27 by Loïc d'Anterroches filed under News.

Petite astuce toute simple pour avoir l’équivalent de ucwords pour de l’utf8:

function mb_ucwords($str)
{
    return mb_convert_case($str, MB_CASE_TITLE, 'UTF-8');
}

À utiliser ainsi par exemple :

$titre = mb_ucwords(mb_strtolower($titre));

En effet, j’ai souvent des gens qui envoie des articles avec le TITRE TOUT EN MAJUSCULES et je n’aime pas cela. Donc je fais ce petit test :

if ($titre == mb_strtoupper($titre)) {
    $titre = mb_ucwords(mb_strtolower($titre));
}

Comments from readers

Voice your ideas

It is painless and I try not to kill electrons in the process.


Your email is required but will not be shared nor displayed.


Do you think your comment will force me to write even better stuff next time? If so, you simply rock.


Logo of Plume CMS