string - Uppercase for first letter with php -
how can convert uppercase following example :
title-title-title
result should be:
title-title-title
i tried ucwords converts this: title-title-title
i have this:
echo $title = ($this->session->userdata('head_title') != '' ? $this->session->userdata('head_title'):'our home page');
in particular string example, explode strings first, use function ucfirst()
, apply exploded strings, put them again:
$string = 'title-title-title'; $strings = implode('-', array_map('ucfirst', explode('-', $string))); echo $strings;
should straightforward on applying this:
$title = ''; if($this->session->userdata('head_title') != '') { $raw_title = $this->session->userdata('head_title'); // title-title-title $title = implode('-', array_map('ucfirst', explode('-', $raw_title))); } else { $title = 'our home page'; } echo $title;
Comments
Post a Comment