Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    Regular Coder Jesper Møller's Avatar
    Join Date
    Jun 2006
    Location
    Denmark, Copenhagen
    Posts
    138
    Thanks
    9
    Thanked 0 Times in 0 Posts

    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 ?
    Last edited by Jesper Møller; 02-15-2010 at 05:44 AM.
    "True knowledge exists in knowing that you know nothing."

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

  • #2
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,411
    Thanks
    13
    Thanked 357 Times in 353 Posts
    mb_convert_case() should do that, but I couldn’t get it to run successfully, tho.
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer

  • #3
    Senior Coder
    Join Date
    May 2005
    Posts
    2,137
    Thanks
    96
    Thanked 72 Times in 72 Posts
    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?

  • #4
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,411
    Thanks
    13
    Thanked 357 Times in 353 Posts
    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.
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer

  • #5
    Regular Coder Jesper Møller's Avatar
    Join Date
    Jun 2006
    Location
    Denmark, Copenhagen
    Posts
    138
    Thanks
    9
    Thanked 0 Times in 0 Posts
    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!"

  • #6
    Regular Coder Jesper Møller's Avatar
    Join Date
    Jun 2006
    Location
    Denmark, Copenhagen
    Posts
    138
    Thanks
    9
    Thanked 0 Times in 0 Posts
    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!"

  • #7
    Regular Coder Jesper Møller's Avatar
    Join Date
    Jun 2006
    Location
    Denmark, Copenhagen
    Posts
    138
    Thanks
    9
    Thanked 0 Times in 0 Posts
    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!"

  • #8
    Regular Coder Jesper Møller's Avatar
    Join Date
    Jun 2006
    Location
    Denmark, Copenhagen
    Posts
    138
    Thanks
    9
    Thanked 0 Times in 0 Posts
    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!"


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •