Removing Lower Case and replacing with Upper Case

Discussion in 'Site & Server Administration' started by swapshop, May 7, 2007.

Thread Status:
Not open for further replies.
  1. #1
    We users place adverts they sometimes add with all lower or worst all upper case

    Need a piece of code like as a starting point

    $sitetitle = ereg_replace("([A-Z]+) ¦ ([a-z]+) ¦ ([0-9]+)", "", $sitetitle);

    Sitetitle reads

    for sale or FOR SALE

    Need to have

    For Sale


    Any ideas please?
     
    swapshop, May 7, 2007 IP
  2. Golfboards

    Golfboards Peon

    Messages:
    122
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Try strtoupper. Ex:

    <?php
    $str = "for sale";
    $str = strtoupper($str);
    echo $str; // Prints FOR SALE
    ?>
     
    Golfboards, May 7, 2007 IP
  3. swapshop

    swapshop Peon

    Messages:
    656
    Likes Received:
    34
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Good start but

    Sitetitle reads

    for sale or FOR SALE

    Need

    For sale

    Or

    For Sale
     
    swapshop, May 7, 2007 IP
  4. Golfboards

    Golfboards Peon

    Messages:
    122
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Oops sorry, I misread your post. But the answer is still prety easy. You want to use strtolower() on the string to convert it to all lower case, then you can use ucwords() on it.

    $str = ucwords(strtolower($str));

    You may need some variation of that for your particular case but that should give you the right direction.

    EDIT: Forgot to mention in case it wasn't obvious - the ucwords() function capitalizes the first letter of each word in a strong. So what we're doing here is converting the string (no matter if it already is lower case) to all lower case, then capitalizing the first letter of each word in the string.
     
    Golfboards, May 7, 2007 IP
  5. swapshop

    swapshop Peon

    Messages:
    656
    Likes Received:
    34
    Best Answers:
    0
    Trophy Points:
    0
    #5
    100% corect awesome!!!!


    $str = ucwords(strtolower($str)); worked a treat.


    Next issue is in a form.

    We have a lot of user just copy and paste with out a carriage return.

    This makes it look ugly.

    How can we automatically achieve a prettier look

    Ie

    Sell Nokia N95 For 265usd Brand New Unlocked. Send your order now. We look forward to your soonest patronage

    We want to have

    Sell Nokia N95 For 265usd
    Brand New Unlocked
    Send your order now
    We look forward to your soonest patronage

    We have a function that starts a new line if a carriage return is entered

    Any ideas to start us off with?

    Also is there a easy well to introduce a spell checker into a form?
     
    swapshop, May 8, 2007 IP
Thread Status:
Not open for further replies.