简体   繁体   English

将php标签转换为html标签输出

[英]php tags into html tags output

I have this code 我有这个代码

$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("juliver", $con);

$result = mysql_query("SELECT * FROM menu");

$sm = "";
while($row = mysql_fetch_array($result))
{

$sm .= "<li><a href='#".$row['page'].'">'.$row['menulist']."</a></li>";

}

mysql_close($con);

?>
<? echo $sm; ?>

My database is look like this. 我的数据库看起来像这样。

id    menulist          page
1     Home              tb1
2     Gallery           tb2
3     Clothing          tb3
4     Furniture         tb4
5     Household-items   tb5

the output should be this if converted into html. 如果转换为html,则输出应为this。

<li><a href="#tb1">Home</a></li>
<li><a href="#tb2">Gallery</a></li>
<li><a href="#tb3">Clothing</a></li>
<li><a href="#tb4">Furniture</a></li>
<li><a href="#tb5">Household-items</a></li>

I tried removing, adding, renaming and etc into the code and etc. but im still stuck and none of them work. 我尝试删除,添加,重命名等到代码等中,但是即时消息仍然停留在其中,但它们均不起作用。

please help me. 请帮我。

Your quotes seem to be muddled up. 您的报价似乎糊涂了。 Your literal text should be enclosed in double quotes (since they appear first), and everything else use single quotes: 您的文字文本应该用双引号引起来(因为它们首先出现),其他所有内容都使用单引号:

$sm .= "<li><a href='#".$row['page']."'>".$row['menulist']."</a></li>";

results in 结果是

$sm .= "<li><a href='#tb1'>Home</a></li>";

which you can then output. 然后可以输出。

You might want to add a \\n in there as well, to format the output nicely. 您可能还想在其中添加一个\\n ,以便很好地格式化输出。

$sm .= "<li><a href='#".$row['page']."'>".$row['menulist']."</a></li>\\n";

我认为您可能没有打开php_short_tags!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM