我正在尝试通过表单将一些 html 发布到 php 页面,然后尝试将该 html 保存到数据库中 我面临的问题是,当我将其保存到数据库时,它包含许多 html 实体
例如我原来的html代码是
<div class="flexslider">
<ul class="slides">
<li class="slide slide--text" data-text="Great Plans And Pricing To Help You Get Started With Your E-Commerce Business">
<div class="overdiv" style="position: absolute;">
<form method="post" action="https://www.marclick.com/customer/account/create/">
<div>
<input required type="email" name="email" value="" style="border-radius:10px;" class="form-control" placeholder="Your Email">
<div class="text-left"></div>
<input type="submit" value="Get Your Online Shop Now!" class="btn btn-warning btn--decorated">
</div>
</form>
<p class="text-left">No Credit Card Required</p>
</div>
<img src="img/home_slider/1.jpg" alt="">
</li>
</ul>
但是当我将其保存到数据库时,它就变成了
<p><!-- Flex full width slider --><br />
<div class="flexslider"><br />
<br />
<ul class="slides"><br />
<li class="slide slide--text" data-text="Great Plans And Pricing To Help You Get Started With Your E-Commerce Business"><br />
<div class="overdiv" style="position: absolute;"><br />
<h2>Get a <span style="color:#E92803;-webkit-text-stroke-width: 1px;-webkit-text-stroke-color: black">FREE</span> Gorgeous Shop in Minutes and Sell Anywhere.</h2><br />
<form method="post" action="https://www.marclick.com/customer/account/create/"><br />
<div><br />
<input required type="email" name="email" value="" style="border-radius:10px;" class="form-control" placeholder="Your Email"><br />
<div class="text-left"></div><br />
<input type="submit" value="Get Your Online Shop Now!" class="btn btn-warning btn--decorated"><br />
</div><br />
</form><br />
<p class="text-left">No Credit Card Required</p><br />
</div><br />
<img src="img/home_slider/1.jpg" alt=""><br />
</li></p>
我应该如何保存html原样并在需要时将其作为html代码回显
这是我的 PHP 代码
$content=$_POST['editor1']; //html
$seo=addslashes($_POST['keywords']);
$category=addslashes($_POST['category']);
$query="INSERT INTO `pages`(`name`,`link`,`seo`,`content`, `category`)
VALUES
('$title','$permalink','$seo','$content','$category')";
$result=mysqli_query($link, $query);
htmlspecialchars社区警告:以下答案具有误导性。 HTML 在存储在 MySQL 数据库中时不需要任何特殊处理,这样的编码/解码将是毫无意义的甚至是有害的。 HTML 代码必须像任何其他数据一样使用准备好的语句进行处理。虽然任何问题都必须具体调查,例如开篇文章中的一些其他代码,与 MySQL 完全无关,添加了这些
您可以将
s.
和 htmlspecialchars_decode 与 htmlEntities 、html_entity_decode 结合使用
htmlspecialchars — 将特殊字符转换为 HTML 实体
请参阅此处的文档
请参阅此处的文档http://php.net/manual/en/function.htmlspecialchars-decode.php
$htmlcode = htmlentities(htmlspecialchars(thehmldata));
echo $htmlcode;
echo html_entity_decode(htmlspecialchars_decode($htmlcode));
$content=htmlentities($_POST['editor1']);
插入之前。 并使用“echo”在页面上直接打印它。