Ucfirst doesnt work on non-english characters

mb_ucfirst
mb_ucwords
php kebab case
mb_case_title_simple
mb_convert_case
php ucwords hyphen
php ucwords unicode
php snake case

I'm trying to make the first letter uppercase in a string. It works fine for english letters, but unfortunetely, it doesn't work on non-english chars, for example

echo ucfirst("çağla");

What is the correct way to make ucfirst work properly on all words including non-english chars ?

For a single word, the right way is: mb_convert_case with MB_CASE_TITLE in second argument.

mb_internal_encoding('UTF-8');

echo mb_convert_case('çağla', MB_CASE_TITLE);

Because it depends on the charset and locale: some languages distinguish uppercase to titlecase. Here, titlecasing is more appropriate.

An example: the digram character dz. Which becomes DZ in uppercase but Dz in titlecase. This is not the same thing.

Note: mb_convert_case + MB_CASE_TITLE alone is equivalent to ucwords. The strict equivalent of ucfirst would be:

return mb_convert_case(mb_substr($str, 0, 1), MB_CASE_TITLE) . mb_substr($str, 1);

ucfirst - Manual, For instance, in the default "C" locale characters such as umlaut-a (�) will not be for anyone wanting to ucfirst each word in a sentence this works for me: Non ASCII characters in the function are in HEX format to avoid encoding issue. /** * ucfirst() function for multibyte character encodings * * @param $string * @param string $encoding * @return string */ function mb_ucfirst($string, $encoding

In newer PHP-Versions PHP work internally with UTF-8. So if you have a string that is not UTF-8 you cat get problems in some functions like htmlspecialchars for example.

Perhaps here is it a same problem. You can try to convert your string to utf-8 first with utf8_encode.

I think the default language is C.

Note that 'alphabetic' is determined by the current locale. For instance, in the default "C" locale characters such as umlaut-a (ä) will not be converted.

http://php.net/manual/de/function.ucfirst.php

If you scroll down you get a function to convert it.

mb_convert_case - Manual, Example #2 mb_convert_case() example with non-Latin UTF-8 text this function doesn't handle UTF-8 characters, I simply tried to replace ucfirst to mb_convert_case, For my case following did the work to capitalize UTF-8 encoded string. Returns a string with the first character of str capitalized, if that character is alphabetic. Note that 'alphabetic' is determined by the current locale. For instance, in the default "C" locale characters such as umlaut-a (ä) will not be converted.

Thanks, I finally found this working function as Stony's suggestion.

function myucfirst($str) {
    $fc = mb_strtoupper(mb_substr($str, 0, 1));
    return $fc.mb_substr($str, 1);
}

mb_convert_case, Example #2 mb_convert_case() example with non-Latin UTF-8 text version of this function doesn't handle UTF-8 characters, I simply tried to replace ucfirst Now it works fine for utf-8 strings as well, except for string delimiters followed by an� Definition and Usage. The ucfirst() function converts the first character of a string to uppercase. Related functions: lcfirst() - converts the first character of a string to lowercase

please try $string = mb_strtoupper($string[0]) . mb_substr($string, 1);

perlunicode, While Perl does not implement the Unicode standard or the accompanying technical reports from You must convert your non-ASCII, non-UTF-8 Perl scripts to be UTF-8. The chr() and ord() functions work on whole characters. lcfirst() , uc() , ucfirst() , and fc (or their double-quoted string inlined versions such as \U ). How to Fix Language Problem of Non-Unicode Program in Windows 10 ? You can fix this problem by changing the language settings for non-unicode programs: To do this, go to the control panel – Open

I made it a oneliner.

function mb_ucfirst($str) {
  return mb_strtoupper(mb_substr($str, 0, 1)).mb_substr($str, 1, mb_strlen($str));
}

PHP ucfirst() Function, echo ucfirst("hello world!"); ?> Try it Yourself �. Definition and Usage. The ucfirst() function converts the first character of a string� 1) A user creates a document using a non-unicode font, entering characters to represent scientific notations. For example, he enters a Mu (µ). Note: I pasted in a unicode-compliant Mu for reference. 2) The user opens his document and attempts to copy / paste this non-unicode character representing a Mu into a web browser for entry into our system.

Strings, But single or double quotes do not work this way. Some rare characters are encoded with two unicode symbols, taking 4 bytes. Write a function ucFirst(str) that returns the string str with the uppercased first character, for� Microsoft Excel is unable to properly display UTF-8 compliant CSV files when they contain non-English characters. To resolve this issue, please do the following after saving the CSV file from Accompa. On a Windows machine: Method 1. On a Windows computer, open the CSV file using Notepad. Click "File > Save As".

Changing string case: strtoupper(), strtolower(), ucfirst(), and , From that, you should be able to see that in calls such as ucwords(), PHP will not change existing capital letters to lowercase, which is why $d and $e are different -� Keyboard special characters not working correctly On the computer my elementary aged son uses, the special characters are not coming out correctly. 2 is ", 6 is &, 7 is /, 8 is (, 9 is ), 0 is =, the key to the right of 0 is incorrect in both normal and shifted ' ?, the equals sign is ¿ and ?

Text Helper — CodeIgniter 4.0.4 documentation, The Text Helper file contains functions that assist in working with Text. including high ASCII and MS Word characters that can cause problems when used in Useful when non-English characters need to be used where only standard ASCII� displaying cyrillic characters with Knitr. Knitr is great. It will take R code and combine it with markdown, allowing you to create ready formatted webpages with calculations and graphics created on the fly from R. But it doesn't work properly with non ascii characters. The solution: Don't use R-studio's built in knitr to html (ctrl-shift-h).

Comments