我将如何设计回声?

我想知道如何在 php 中设置 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;

}


收到一只叮咚
浏览 114回答 2
2回答

呼如林

更好的是,不要从您的 php 逻辑中进行演示。考虑一下:<?php&nbsp;if(!isset($_SESSION['sess_user_id']) || $_SESSION['sess_user_name'] == "") {&nbsp; &nbsp; 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>

回首忆惘然

你有语法错误。echo&nbsp;"<p&nbsp;id="profileText"This&nbsp;is&nbsp;your&nbsp;personal&nbsp;profile&nbsp;page,&nbsp;from&nbsp;here&nbsp;you&nbsp;can&nbsp;edit&nbsp;events</p>";在您的回声中使用单引号。echo&nbsp;"<p&nbsp;id='profileText'>This&nbsp;is&nbsp;your&nbsp;personal&nbsp;profile&nbsp;page,&nbsp;from&nbsp;here&nbsp;you&nbsp;can&nbsp;edit&nbsp;events</p>";如果您在回显中使用双引号,则不能在字符串中使用另一个双引号。你可以这样做:echo&nbsp;"<p&nbsp;id=\"profileText\">&nbsp;This&nbsp;is&nbsp;your&nbsp;personal&nbsp;profile&nbsp;page,&nbsp;from&nbsp;here&nbsp;you&nbsp;can&nbsp;edit&nbsp;events</p>";或者你可以在你的字符串上使用单引号echo&nbsp;"<p&nbsp;id='profileText'>This&nbsp;is&nbsp;your&nbsp;personal&nbsp;profile&nbsp;page,&nbsp;from&nbsp;here&nbsp;you&nbsp;can&nbsp;edit&nbsp;events</p>";
打开App,查看更多内容
随时随地看视频慕课网APP