Skip to content
Advertisement

How to capitalize a word that has all letters in as capital letters in css OR php

I have the following code and using css text-transform property with a value of capitalize or php ucwords() I get the title capitalized but when the title is provided with all letters as capitals it doesn’t work. How can I achieve the output to be capitalized regardless of the title provided?

  <h4 style="text-transform: capitalize;">
      <a href="{{ route('posts.show', $post )}}">{{ $post->title }}</a>
  </h4>

Advertisement

Answer

A php solution would be to convert case to lower and then use ucfirst

$text = 'THIS IS A TITLE';
$normalText = ucfirst(strtolower($text));
echo $normalText;
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement