Skip to content

Instantly share code, notes, and snippets.

@burakerdem
Created June 4, 2011 01:38
Show Gist options
  • Save burakerdem/1007450 to your computer and use it in GitHub Desktop.
Save burakerdem/1007450 to your computer and use it in GitHub Desktop.
PHP: ucwords() for UTF-8 strings
<?php
if (!function_exists('mb_ucwords'))
{
function mb_ucwords($str)
{
return mb_convert_case($str, MB_CASE_TITLE, "UTF-8");
}
}
@vuhanguyen
Copy link

Thanks, it helps me solve the problem of ucwords with Vietnamese UTF-8 strings

@francescom
Copy link

francescom commented Nov 7, 2022

You have to mb_strtolower, before.

<?php

if (!function_exists('mb_ucwords'))
{
	function mb_ucwords($str,$encoding='UTF-8')
	{
		return mb_convert_case(mb_strtolower($str, $encoding), MB_CASE_TITLE, $encoding);
	}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment