使 PHP 输出加粗
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20741876/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Making PHP output Bold
提问by Brian J Kirk
I am having trouble figuring out how to make my php output bold, I have tried but I receive and error when I try that. I have tried to search this topic but none of the answers seem to be helping me in my situation.
我在弄清楚如何使我的 php 输出加粗时遇到了麻烦,我试过了 但是当我尝试时,我收到并出错。我试图搜索这个话题,但在我的情况下,似乎没有一个答案对我有帮助。
while($row = mysql_fetch_array($oPlayerInfo))
{
Print "".$row['FirstName']." ".$row['LastName']."<br>";
Print "Position: ".$row['Position']."<br>";
Print "Height: ".$row['Height']."<br>";
Print "Weight: ".$row['Weight']."<br>";
Print "Birthdate: ".$row['DOB']."<br>";
Print "CNGHL Team: ".$row['CNGHLRights']."<br>";
Print "NHL Team: ".$row['Team']."<br>";
Print "Draft Year: ".$row['CNDraftYR']."<br>";
Print "Draft Position: ".$row['CNDraftPOS']."<br>";
Print "Drafted By: ".$row['CNDraftTEAM']."<br>";
Print "<img src=\"http://www.cnghl.biz/cnghldb/images/".$iPlayerID.".jpg\">";
回答by The Humble Rat
Simply add HTML strong tags into your print, removing on lines where it is not necessary.
只需将 HTML 强标签添加到您的打印中,删除不需要的行。
while($row = mysql_fetch_array($oPlayerInfo))
{
Print "<strong>".$row['FirstName']." ".$row['LastName']."</strong><br>";
Print "<strong>Position: ".$row['Position']."</strong><br>";
Print "<strong>Height: ".$row['Height']."</strong><br>";
Print "<strong>Weight: ".$row['Weight']."</strong><br>";
Print "<strong>Birthdate: ".$row['DOB']."</strong><br>";
Print "<strong>CNGHL Team: ".$row['CNGHLRights']."</strong><br>";
Print "<strong>NHL Team: ".$row['Team']."</strong><br>";
Print "<strong>Draft Year: ".$row['CNDraftYR']."</strong><br>";
Print "<strong>Draft Position: ".$row['CNDraftPOS']."</strong><br>";
Print "<strong>Drafted By: ".$row['CNDraftTEAM']."</strong><br>";
Print "<img src=\"http://www.cnghl.biz/cnghldb/images/".$iPlayerID.".jpg\">";
}
With this
有了这个
Print "<strong>Height: ".$row['Height']."</strong><br>";
The whole line will be bold. With the one below
整条线将是粗体。与下面的
Print "<strong>Height:</strong> ".$row['Height']."<br>";
Only the label will be bold.
只有标签是粗体的。
回答by Bhushan
Try this to make firstname and lastname bold.
试试这个让名字和姓氏加粗。
Print "<b>".$row['FirstName']." ".$row['LastName']."</b><br>"; //<b> and </b>
回答by Shankar Damodaran
Try like this...
试试这样...
<?php
while($row = mysql_fetch_array($oPlayerInfo))
{
echo "<strong>"; // <---- Added here
echo "".$row['FirstName']." ".$row['LastName']."<br>";
echo "Position: ".$row['Position']."<br>";
echo "Height: ".$row['Height']."<br>";
echo "Weight: ".$row['Weight']."<br>";
echo "Birthdate: ".$row['DOB']."<br>";
echo "CNGHL Team: ".$row['CNGHLRights']."<br>";
echo "NHL Team: ".$row['Team']."<br>";
echo "Draft Year: ".$row['CNDraftYR']."<br>";
echo "Draft Position: ".$row['CNDraftPOS']."<br>";
echo "Drafted By: ".$row['CNDraftTEAM']."<br>";
echo "</strong>"; // <-----Closing here
echo "<img src=\"http://www.cnghl.biz/cnghldb/images/".$iPlayerID.".jpg\">";
}
回答by José Ramírez
Well, I think that putting such an operation in an HTML file, it is a bad practice. I recommend using the MVCpattern.
嗯,我认为把这样的操作放在一个 HTML 文件中,这是一个不好的做法。我推荐使用MVC模式。
Something like this...
像这样的东西...
Controller
控制器
<?php
$rows = array();
while($row = mysql_fetch_array($oPlayerInfo))
$rows[] = $row;
return $rows;
?>
View
看法
<html>
<head><title>Test</title></head>
<body>
<?php foreach($rows as $row): ?>
<section>
<div>
<label>$row['FirstName']." ".$row['LastName']</label>
</div>
<div>
<label>Position: ".$row['Position']</label>
</div>
<div>
<label>"Height: ".$row['Height']</label>
</div>
<div>
<label>Weight: ".$row['Weight']</label>
</div>
<div>
<label>Birthdate: ".$row['DOB']</label>
</div>
<div>
<label>CNGHL Team: ".$row['CNGHLRights']</label>
</div>
<div>
<label>NHL Team: ".$row['Team']</label>
</div>
<div>
<label>Draft Year: ".$row['CNDraftYR']</label>
</div>
<div>
<label>Draft Position: ".$row['CNDraftPOS']</label>
</div>
<div>
<label>Drafted By: ".$row['CNDraftTEAM']</label>
</div>
<div>
<img src="http://www.cnghl.biz/cnghldb/images/".$iPlayerID.".jpg">
</div>
</section>
<?php endforeach; ?>
</body>
</html>
回答by Simon Davies
you can try adding the b or strong tag to your print outputs as:
您可以尝试将 b 或 strong 标签添加到您的打印输出中:
Print "<strong>Height: ".$row['Height']."</strong><br>";
Or for the whole element as @Shankar Damodaran has posted?
或者对于@Shankar Damodaran 发布的整个元素?

