Hi,

i have a string for example

"hello, how are you?"

what i want to be able to do is change the first char of the string for a different one, in this case a "H" so i can format the sentence.

cheers

    Hi

    Thanks for that bit of code 🙂, however seem to have a problem, its wont work on an varible held in an array..

    i have event tryied setting up a temp varible which equals that in my array, and then run the ucfirst command on that with still no luck..

    $temp = $group['sentence'][$n];
    echo ucfirst($temp) ;
    

      ah please ignore last comment, seems i had a blank space at the front lol

        n_wattam wrote:

        ah please ignore last comment, seems i had a blank space at the front lol

        That's actually fortuitous. If you aniticipate encountering that problem again, you can trim() the string first to remove excess spaces:

        echo ucfirst(trim($temp)) ;

          Or you could use a little bit of regular expression to simply capitalize the first letter, wherever it may appear in the string...

          $temp = preg_replace('/^([^a-z]*)([a-z])/ei', '"$1" . strtoupper("$2")', $group['sentence'][$n]);
            Write a Reply...