[英]How to display php code and html tags as text in a web page
I have the following piece of code and wish to display it as text in a webpage.我有以下一段代码,并希望将其显示为网页中的文本。 How can I do it?
我该怎么做? I wat the code mentioned below to be displayed as text in a webpage.
我看下面提到的代码在网页中显示为文本。 The page might be either a .html page or a .php page.
该页面可能是 .html 页面或 .php 页面。 Kindly help.
请帮忙。
<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>
You can also use highlight_string() function您还可以使用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;
please change your variables请更改您的变量
if your server isn't set up to process .html for the php tag, you're fine to do exactly what you've done.如果您的服务器没有设置为处理 php 标记的 .html,那么您可以完全按照您所做的去做。
You can also use this: <?php
which would render as <?php
but not be seen by PHP.你也可以使用这个:
<?php
它将呈现为<?php
但不被 PHP 看到。
One option you can use is PHP's highlight_file()
function:您可以使用的一种选择是 PHP 的
highlight_file()
函数:
<?php
highlight_file("your_file.php");
?>
You can also use .html
file extensions highlight_file("your_file.html")
.您还可以使用
.html
文件扩展名highlight_file("your_file.html")
。
Even a .txt
file extension highlight_file("your_file.txt")
.即使是
.txt
文件扩展名highlight_file("your_file.txt")
。
Consult:咨询:
this question is pretty old , but as long as no one used this solution so this would be helpful .这个问题已经很老了,但只要没有人使用这个解决方案,这就会有所帮助。
using htmlspecialchars :使用htmlspecialchars :
htmlspecialchars — Convert special characters to HTML entities
htmlspecialchars — 将特殊字符转换为 HTML 实体
echo htmlspecialchars("your special character goes here");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.