关于MySQL变量的回声的PHP ucwords

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

我从MySQL查询中得到以下php echo,除了城市在数据库中都是大写之外。 / p>

参考PHP手册此处 ,看起来ucwords应该适合账单吗? p>

Works: p>

  echo($ row ['City']); 
   pre> 
 
 

我试过这个,但它仍然将城市全部显示为大写? p>

  echo ucwords($ row ['City'  ]); 
  code>  pre> 
  div>

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