Jesper Møller
02-13-2010, 06:30 PM
Im making a small form wher peapol type ther name, surname, address and so on. And i woud like the names to always end op with capital first letter so i didt this
$firstname = ucwords(trim($_POST['firstname']));
And it works well except for æøåäëö and others special characters
How can i make shure that those kind of letters gets captial ?
Dormilich
02-13-2010, 07:24 PM
mb_convert_case() should do that, but I couldn’t get it to run successfully, tho.
masterofollies
02-13-2010, 08:42 PM
That tag is for PHP 4.3.0 to PHP 5. So if you have less than 4.3.0 it won't be valid.
Dormilich
02-13-2010, 09:22 PM
So if you have less than 4.3.0 it won't be valid.
poor fellow, if he still has to work with PHP 4.
Jesper Møller
02-13-2010, 11:32 PM
Ill look in to that mb_convert_case()
(i got php5 :) )
Jesper Møller
02-15-2010, 04:35 AM
Well it looks like i can use that some places but not all
for some inputs (eg. in textarea) its only the first letter in the text i want to capitalise
Cant se anny code for that
( ucfirst() dont work on special charactes either )
Jesper Møller
02-15-2010, 05:43 AM
Ok ... this looks more dificult than i was thinking
it works well when used on a singel word or lines wher all words shal be capitalised
but if only the first word in sentens it gets dificult :rolleyes:
for a text area i tryde this
$infotext = ucfirst(trim($_POST["infotext"]));
works well except for special letters like æøå :rolleyes:
so i tryde this
$infotext = trim($_POST["infotext"]);
$infotext = substr($infotext,0,1);
$infotext = mb_convert_case($infotext, MB_CASE_TITLE, "utf-8");
well it will capitalise the first letter .. but æøå simply disapers :eek: (and so dos the rest of the text, but that can be solvd with some extra code)
æø and å (and other special characters) is actualy 2letters/sign, so by looking at the 2 first insted of the first it actualy works :)
$infotext = substr($infotext,0,2);
so i end up with this:
$infotext = trim($_POST["infotext"]);
$infotext = mb_convert_case(substr($infotext,0,2), MB_CASE_TITLE, "utf-8").substr($infotext,2);
Testet with letters like æøåöäé
maby others can benifit of my strukel :D
(now ill try to se if i can get the 2 lines combind) :cool:
Jesper Møller
02-15-2010, 05:50 AM
Combining those to lines was easyer than expected :cool:
$infotext = mb_convert_case(substr((trim($_POST["infotext"])),0,2), MB_CASE_TITLE, "utf-8").substr($_POST["infotext"],2);
or if both start and end of line shud be trimd:
$infotext = mb_convert_case(substr((trim($_POST["infotext"])),0,2), MB_CASE_TITLE, "utf-8").substr((trim($_POST["infotext"])),2);
:thumbsup: