我有以下一段代码,并希望在网页中将其显示为文本。我该怎么做?我把下面提到的代码显示为网页中的文本。该页面可以是.html页面,也可以是.php页面。请帮忙。
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Log in!</title>
<style type="text/css">
div {
width:300px;
height:120px;
margin: 0px auto;
margin-top: 100px;
padding: 30px 20px;
border:2px solid #00F;
background-color:#0CF;
border-radius:10px;
}
span{
margin:0px auto;
color:#F00;
font-family:Verdana, Geneva, sans-serif;
font-size:12px;
}
</style>
</head>
<body>
</body>
<?php
require_once('conn.php');
$sql="select * from contacts where contacts_id=14";
$result=$mysqli->query($sql);
$row=$result->fetch_array();
if( isset($_POST['id']) && $row['email']==$_POST['id'] && $_POST['password']==$row['password'])
{
header("location:view.php") ;
$_SESSION['sid']= $row['email'];
$flag=1;
}
?>
<div>
<form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
<table align="center" border="0">
<tr>
<td>Id</td>
<td>:</td>
<td><input type="text" name="id" placeholder="Email" /></td>
</tr>
<tr>
<td>Password</td>
<td>&:</td>
<td><input type="password" name="password" /></td>
</tr>
<tr>
<td></td>
<td colspan="2"><input type="submit" value="Log In!" /></td>
</tr>
</table>
</form>
<?php
if (isset($_POST['id']) && isset($_POST['password']) && $flag==0)
{
echo "<center><span>Invalid Id/Password</span></center>";
}
?>
</div>
</body>
</html>
你也可以
使用 highlight_string() 功能
<?php
highlight_string("YOUR STRING/CODE GOES HERE");
?>
$gen_query_data= htmlspecialchars(' $'.$db_val_clean.'_ser = $_POST["'.$sel_name_clean.'_ser"];')."<br>";
echo $gen_query_data;
请更改您的变量
如果你的服务器没有设置为处理 php 标签的.html,你可以完全按照你所做的去做。
你也可以使用这个:<?php
,它会呈现为<?php
但不会被 PHP 看到。
你可以
使用的一个选项是PHP的highlight_file()
函数:
<?php
highlight_file("your_file.php");
?>
您还可以使用.html
文件扩展名highlight_file("your_file.html")
。
即使是.txt
的文件扩展名highlight_file("your_file.txt")
.
咨询:
- http://php.net/manual/en/function.highlight-file.php
这个问题
已经很老了,但只要没有人使用这个解决方案,所以这将是有帮助的。
使用 htmlspecialchars :
htmlspecialchars — 将特殊字符转换为 HTML 实体
echo htmlspecialchars("your special character goes here");