gpt4 book ai didi

php - 我将如何处理 echo 样式?

转载 作者:行者123 更新时间:2023-11-28 16:50:43 26 4
gpt4 key购买 nike

我想知道如何在 php 中设置 echo 样式?我正在尝试设置嵌套在其中一个 echo 中的段落标签的样式,如果有人能告诉我如何做到这一点,我将不胜感激。谢谢

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;
}

最佳答案

更好的是,不要在您的 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 代码
  • 您不必担心单引号/双引号/转义引号/废话,废话,废话。
  • 您不必担心 header 之前的输出
  • 继您之后的程序员会对您的代码如此干净感到惊讶:)
  • 它可以让您轻松看到拼写错误:<p id="profileText"This is your personal profile page, from here you can edit events</p>

关于php - 我将如何处理 echo 样式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59094111/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com