Skip to content
Advertisement

PHP strtolower ignoring the first character

I am looking for a way in which each word from the 2nd letter to write everything small. The first letter should be ignored. Does anyone have an idea?

<?php
    $string = "This is a GREAT String";
    echo " . strtolowerbutnotthefirst($string) . "; // This is a Great String
?>

Advertisement

Answer

You have to write your own function to do this. Use something like the following:

<?php

function lcwords_ignore_first(&$word, $key)
{
    $word = $word[0] . strtolower(substr($word, 1));
}

$string = "This is a GREAT String";
$words = explode(" ", $string);
array_walk($words, 'lcwords_ignore_first');
echo implode(" ", $words); // Output: This is a Great String
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement