Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-13-2010, 06:30 PM   PM User | #1
Jesper Møller
Regular Coder

 
Join Date: Jun 2006
Location: Denmark, Copenhagen
Posts: 132
Thanks: 8
Thanked 0 Times in 0 Posts
Jesper Møller is an unknown quantity at this point
Thumbs up How to make special characters Capital ?

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

PHP Code:
$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 ?
__________________
"True knowledge exists in knowing that you know nothing."

"Education is learning what you didn't even know you didn't know!"

Last edited by Jesper Møller; 02-15-2010 at 05:44 AM..
Jesper Møller is offline   Reply With Quote
Old 02-13-2010, 07:24 PM   PM User | #2
Dormilich
Senior Coder

 
Dormilich's Avatar
 
Join Date: Jan 2010
Location: Behind the Wall
Posts: 2,855
Thanks: 9
Thanked 288 Times in 284 Posts
Dormilich is on a distinguished road
mb_convert_case() should do that, but I couldn’t get it to run successfully, tho.
__________________
please post your code wrapped in [CODE] [/CODE] tags
Dormilich is offline   Reply With Quote
Old 02-13-2010, 08:42 PM   PM User | #3
masterofollies
Senior Coder

 
Join Date: May 2005
Posts: 2,137
Thanks: 96
Thanked 72 Times in 72 Posts
masterofollies can only hope to improve
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.
__________________
Rowsdower! has accused me of having mental problems, and the administrator allowed it. What a great forum huh?
masterofollies is offline   Reply With Quote
Old 02-13-2010, 09:22 PM   PM User | #4
Dormilich
Senior Coder

 
Dormilich's Avatar
 
Join Date: Jan 2010
Location: Behind the Wall
Posts: 2,855
Thanks: 9
Thanked 288 Times in 284 Posts
Dormilich is on a distinguished road
Quote:
Originally Posted by masterofollies View Post
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.
__________________
please post your code wrapped in [CODE] [/CODE] tags
Dormilich is offline   Reply With Quote
Old 02-13-2010, 11:32 PM   PM User | #5
Jesper Møller
Regular Coder

 
Join Date: Jun 2006
Location: Denmark, Copenhagen
Posts: 132
Thanks: 8
Thanked 0 Times in 0 Posts
Jesper Møller is an unknown quantity at this point
Ill look in to that mb_convert_case()

(i got php5 )
__________________
"True knowledge exists in knowing that you know nothing."

"Education is learning what you didn't even know you didn't know!"
Jesper Møller is offline   Reply With Quote
Old 02-15-2010, 04:35 AM   PM User | #6
Jesper Møller
Regular Coder

 
Join Date: Jun 2006
Location: Denmark, Copenhagen
Posts: 132
Thanks: 8
Thanked 0 Times in 0 Posts
Jesper Møller is an unknown quantity at this point
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 )
__________________
"True knowledge exists in knowing that you know nothing."

"Education is learning what you didn't even know you didn't know!"
Jesper Møller is offline   Reply With Quote
Old 02-15-2010, 05:43 AM   PM User | #7
Jesper Møller
Regular Coder

 
Join Date: Jun 2006
Location: Denmark, Copenhagen
Posts: 132
Thanks: 8
Thanked 0 Times in 0 Posts
Jesper Møller is an unknown quantity at this point
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

for a text area i tryde this
PHP Code:
$infotext ucfirst(trim($_POST["infotext"])); 
works well except for special letters like æøå

so i tryde this
PHP Code:
$infotext trim($_POST["infotext"]);
$infotext substr($infotext,0,1);
$infotext mb_convert_case($infotextMB_CASE_TITLE"utf-8"); 
well it will capitalise the first letter .. but æøå simply disapers (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
PHP Code:
$infotext substr($infotext,0,2); 
so i end up with this:
PHP Code:
$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

(now ill try to se if i can get the 2 lines combind)
__________________
"True knowledge exists in knowing that you know nothing."

"Education is learning what you didn't even know you didn't know!"
Jesper Møller is offline   Reply With Quote
Old 02-15-2010, 05:50 AM   PM User | #8
Jesper Møller
Regular Coder

 
Join Date: Jun 2006
Location: Denmark, Copenhagen
Posts: 132
Thanks: 8
Thanked 0 Times in 0 Posts
Jesper Møller is an unknown quantity at this point
Combining those to lines was easyer than expected

PHP Code:
$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:
PHP Code:
$infotext mb_convert_case(substr((trim($_POST["infotext"])),0,2), MB_CASE_TITLE"utf-8").substr((trim($_POST["infotext"])),2); 
__________________
"True knowledge exists in knowing that you know nothing."

"Education is learning what you didn't even know you didn't know!"
Jesper Møller is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:21 AM.


Advertisement
Log in to turn off these ads.