-2

我有一些 SQL 字段需要在 PHP 中显示为表格的标题

以下是我的一些字段名称,我想将它们显示为以下字符串

    market_name =>Market Name
 company_name => Company Name 
company_address => Company Address 
operating_hours => Operating hours

那里有任何字符串格式选项吗?

4

2 回答 2

2

您可以组合ucwords()str_replace()产生所需的结果:

代码:

$strings = array('market_name', 'company_name', 'company_address', 'operating_hours');
foreach($strings as $string){
$string = ucwords(str_replace('_', ' ', $string));
echo $string."<br>";
}

输出:

Market Name
Company Name
Company Address
Operating Hours

文档:ucwords(),str_replace()

希望这可以帮助!

于 2013-07-17T11:11:50.897 回答
1

这应该可以解决问题:

$string = "market_name";
//replace the underscore with whitespace
$step1 = str_replace("_", " ", $string);
//capitalize the words
$step2 = ucwords($step1);
//this will give you
Market Name
于 2013-07-17T11:11:22.067 回答