0

I have the following php echo from a MySQL query that works fine except that the city is all uppercase in database.

Referencing the PHP manual here, it appears ucwords should fit the bill?

Works:

echo ($row['City']);

I tried this but it still shows the city as all uppercase?

echo ucwords($row['City']);
steffen
  • 14,490
  • 3
  • 40
  • 77
Rocco The Taco
  • 3,545
  • 11
  • 43
  • 77

4 Answers4

4

How about

echo ucwords(strtolower($row['City']));
steffen
  • 14,490
  • 3
  • 40
  • 77
1

You can lowercase the string before you use ucwords():

$test = 'HELLO WORLD';

echo ucwords(strtolower($test)); // Hello World

Demo: https://eval.in/125365

Note: this specific example is actually in the PHP manual, always pays to check the manual first.

scrowler
  • 23,965
  • 9
  • 60
  • 90
1

Source: http://www.php.net/manual/de/function.ucwords.php

See the docs!

 <?php
      $foo = 'hello world!';
      $foo = ucwords ($foo);          // Hello World!

      $bar = 'HELLO WORLD!';
      $bar = ucwords($bar);             // HELLO WORLD!
      $bar = ucwords(strtolower($bar)); // Hello World!
 ?>
Adrian Preuss
  • 3,069
  • 22
  • 40
-1

I'm not sure why you have the ?> at the end of the line. Try the following:

$word = $row['City'];
echo ucwords(strtolower($word));
aashnisshah
  • 464
  • 4
  • 10