我将如何设计回声的样式?

时间:2019-11-28 17:47:40

标签: php css

我想知道如何在php中设置回声的样式?我试图设置嵌套在回声之一中的段落标签的样式,如果有人可以告诉我该怎么做,我将不胜感激。谢谢

PHP

if(isset($_SESSION['sess_user_id']) && $_SESSION['sess_user_name'] != "") {
echo '<h1>Welcome '.$_SESSION['sess_user_name'].'</h1>';
echo "<p id="profileText"This is your personal profile page, from here you can edit events</p>";
echo '<h4><a href="logout.php">Logout</a></h4>';
} 
else { 
header('location:index.php');

CSS

#profileText {
top: 40%;
position: absolute;
color: blue;
}

2 个答案:

答案 0 :(得分:1)

更好的是,不要从您的php逻辑中进行演示。考虑一下:

<?php 
if(!isset($_SESSION['sess_user_id']) || $_SESSION['sess_user_name'] == "") {
    header('location:index.php');
}

// do any other php stuff...

?>
<h1>Welcome <?= $_SESSION['sess_user_name'] ?></h1>
<p id="profileText">This is your personal profile page, from here you can edit events</p>
<h4><a href="logout.php">Logout</a></h4>

这样

  • 您的逻辑和表达方式明确分开
  • 如果您要更改演示文稿,则不必弄乱php代码
  • 您不必担心单引号/双引号/转义引号/等等,等等,等等。
  • 您不必担心标题之前的输出
  • 您之后的程序员会对代码的干净程度感到惊讶:)
  • 它可让您轻松查看错别字:<p id="profileText"This is your personal profile page, from here you can edit events</p>

答案 1 :(得分:0)

您遇到语法错误。

echo "<p id="profileText"This is your personal profile page, from here you can edit events</p>";

在回声中使用单引号。

echo "<p id='profileText'>This is your personal profile page, from here you can edit events</p>";

如果在回显中使用双引号,则不能在字符串中使用另一个双引号。您可以通过以下方式进行操作:

echo "<p id=\"profileText\"> This is your personal profile page, from here you can edit events</p>";

或者您可以在字符串上使用单引号

echo "<p id='profileText'>This is your personal profile page, from here you can edit events</p>";
相关问题