关于MySQL变量的回声的PHP ucwords

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']);

How about

echo ucwords(strtolower($row['City']));

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.

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

$word = $row['City'];
echo ucwords(strtolower($word));

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!
 ?>