开发者

Make HTML tag in PHP

开发者 https://www.devze.com 2022-12-31 20:01 出处:网络
I have some php code $_SESSION[\'username\'] and I need to display it using html with something like <p>the username h开发者_高级运维ere</p>. I heard you might be able to do this using ech

I have some php code $_SESSION['username'] and I need to display it using html with something like <p>the username h开发者_高级运维ere</p>. I heard you might be able to do this using echo in PHP but Im not sure how. Thanks for any help.


echo '<p>' . $_SESSION['username'] . '</p>';

or

<p><?php echo $_SESSION['username'] ?></p>

You should really run it through htmlspecialchars to avoid breaking your HTML syntax (for example if the user's name contains </p> or something, or if they attempt an XSS attack):

echo '<p>' . htmlspecialchars($_SESSION['username']) . '</p>';


If I understood you correctly, I believe you are looking for:

<p><?php echo $_SESSION['username']?></p>


<?php echo '<p>'.$_SESSION['username'].'</p>'; ?>


Check out the documentation:

http://www.php.net/manual/en/tutorial.useful.php

0

精彩评论

暂无评论...
验证码 换一张
取 消