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
  • 16,138
  • 4
  • 42
  • 81
Rocco The Taco
  • 3,695
  • 13
  • 46
  • 79

4 Answers4

4

How about

echo ucwords(strtolower($row['City']));
steffen
  • 16,138
  • 4
  • 42
  • 81
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
  • 24,273
  • 9
  • 60
  • 92
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,228
  • 1
  • 23
  • 43
-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
  • 468
  • 4
  • 10