我试图张贴一些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>
但是当我保存db时,它变成了
<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和htmlspecialchars_decode与htmlEntities、 htmlentity_decode
结合使用htmlspecialchars -将特殊字符转换为HTML实体
查看这里的文档http://php.net/htmlspecialchars
htmlspecialchars_decode -将特殊的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"打印出来。
有时htmlspecialchars()或htmlentities()在数据库中保存html标记时给出错误,因此不要使用base64_encode()或解码base64_decode()。请参阅所附的
链接https://stackoverflow.com/a/59916834/12489279