1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

PHP - Please Help!

Discussion in 'PHP' started by monkeyclap, Feb 18, 2012.

  1. #1
    Hi, I have the following code to change the capitalisation of some text. For the most part it works great but for text with an apostrophe it needs changing.

    For example it transforms "i don't want to miss a thing" to "I Don'T Want To Miss A Thing" but I want it to be "I Don't Want To Miss A Thing".

    					<?php
    					function make_ucwords_work($string2){
    							$new2 = preg_replace('/\b[a-z]/e', "strtoupper('$0')", $string2);
    							return $new2;
    					}
    					?>
    PHP:
     
    monkeyclap, Feb 18, 2012 IP
  2. Estevan

    Estevan Peon

    Messages:
    120
    Likes Received:
    8
    Best Answers:
    1
    Trophy Points:
    0
    #2
    hello

    try this

    <?php
        function make_ucwords_work($string2){
        $a=explode(" ",strtolower($string2));
        $b = array_map("ucfirst", $a);
        $new2=implode(" ",$b);
        return $new2;
          }
    ?>
    PHP:
    Best
     
    Estevan, Feb 18, 2012 IP
    monkeyclap likes this.
  3. monkeyclap

    monkeyclap Active Member

    Messages:
    832
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    85
    #3
    That's that fixed that problem, but now the first letter in brackets () isn't capitalised... e.g. It's So Hard To Say (live) instead of It's So Hard To Say (Live)

    Any ideas? Thanks
     
    monkeyclap, Feb 18, 2012 IP
  4. ThePHPMaster

    ThePHPMaster Well-Known Member

    Messages:
    631
    Likes Received:
    32
    Best Answers:
    20
    Trophy Points:
    100
    #4
    PHP's built in ucwords should work:

    
    $string = "it's so hard To say (live)";
    echo ucwords($string));
    
    PHP:
     
    ThePHPMaster, Feb 18, 2012 IP
    monkeyclap likes this.
  5. monkeyclap

    monkeyclap Active Member

    Messages:
    832
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    85
    #5
    thanks, done :)
     
    Last edited: Feb 19, 2012
    monkeyclap, Feb 19, 2012 IP