【问题标题】:How to style a echo function with multiple variables如何为具有多个变量的回声函数设置样式
【发布时间】:2019-05-30 08:21:50
【问题描述】:

我希望我的代码在同一个回显函数上显示两个变量,但是,我希望它们具有不同的样式。使“id”更小,颜色不同。我不知道如何分离这两个变量,所以我可以在中间添加一些代码。

我尝试使用第二个回显功能,但“id”显示在底部,与“报价”功能分开。

echo "<p class='dash'>---------</p>","<p class='center' style='color:white' align='center'>" .$row['quote'] .$row['id'];

输出将像这样显示(输出的粗体文本):
--------
“这是引用变量”1


但是,我需要这样显示:

-------
“这是引用变量”
1


所以基本上需要的是某种方式来为第二个添加样式。 (我已经设计了第一个)

【问题讨论】:

  • 这也许是:echo "&lt;p class='dash'&gt;---------&lt;/p&gt;","&lt;p class='center' style='color:white' align='center'&gt;" .$row['quote'] ."&lt;br&gt;".$row['id'];
  • @tim 我之前尝试过,但忘记了“”,无法弄清楚为什么它不起作用。感谢您为我节省了时间!
  • 使用 PHP 连接运算符。用于将两个字符串值组合成一个字符串。

标签: php html echo


【解决方案1】:

另一种不使用点连接运算符的方法:

<?php
$row["quote"] = "This is the quote";
$row["id"] = 1;
$p = [];
$p[0] = "<p class='dash'>---------</p>\n";
$p[1] = "<p class='center' style='color:white' align='center'>$row[quote]<br>\n$row[id]</p>\n";
echo $p[0],$p[1];

直播code here

示例 HTML 实现:

.dash {
  color: blue;
  font-weight: 300;
}

.center {
  text-algin: center font-weight:900;
}

body {
background:navy
}
<p class='dash'>---------</p>
<p class='center' style='color:white' align='center'>This is the quote<br> 1
</p>

【讨论】:

    猜你喜欢
    • 2021-08-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-10
    • 2014-06-09
    • 1970-01-01
    • 1970-01-01
    • 2022-06-11
    相关资源
    最近更新 更多