[英]Insert html content to mysql table
I need to insert html content to mysql table.but script cut part of html content.我需要将 html 内容插入 mysql 表中。但是脚本剪切了 html 内容的一部分。 Html content is as below.
Html 内容如下。
<div data-plugin-lightbox data-plugin-options='{"delegate": "a", "type": "image", "gallery": {"enabled": true}}'>
i cannot upload all content.mysql table has Only我无法上传所有内容。mysql 表只有
<div data-plugin-lightbox data-plugin-options={"
How can i insert any html content to mysql table.如何将任何 html 内容插入 mysql 表。
Seems a double quote related issue .. you should escape the double quote for json 似乎与双引号相关的问题..你应该逃避json的双引号
<div data-plugin-lightbox data-plugin-options='{\"delegate\": \"a\", \"type\": .......
or the issue could be related to your string assignment in php 或者问题可能与你在php中的字符串赋值有关
the assignment 分配
$sql = "< <div data-plugin-lightbox data-plugin-options='{"delegate": "
break on the second double quotes 打破第二个双引号
HTML tegs可以用纯文本插入到mysql中。但是你应该回显你正确插入的内容
use htmlspecialchars($str) before you store in DB. 在存储到DB之前使用htmlspecialchars($ str)。
and use htmlspecialchars_decode($str) after reading from DB. 从DB读取后使用htmlspecialchars_decode($ str)。
Try using htmlspecialchars() on the string to put into the DB, and then, when pulling it back out, use htmlspecialchars_decode(). 尝试在字符串上使用htmlspecialchars()放入DB,然后在将其拉回时,使用htmlspecialchars_decode()。 Might make a difference.
可能会有所作为。
You should always escape your strings before using them in SQL queries, to avoid the kind of problems you have here and for security reasons . 在SQL查询中使用它们之前,应始终转义字符串,以避免出现此类问题并出于安全原因 。
PHP's mysqli extenstion comes with the mysqli_real_escape_string that is here just for this purpose and respects the connection's charset: PHP的mysqli扩展附带了mysqli_real_escape_string ,它仅用于此目的并且尊重连接的charset:
Object oriented style: 面向对象的风格:
$var = $mysqli->real_escape_string($var);
Procedural style: 程序风格:
$var = mysqli_real_escape_string($db_link, $var);
I found a solution. 我找到了解决方案。 Reason is ' & quot ;
原因是'' '.
”。 Used this to avoid var NewString = text.replace(/&/g, "xxx");
用它来避免var NewString = text.replace(/&/ g,“xxx”);
thank you all 谢谢你们
htmlentities($message,ENT_QUOTES ); htmlentities($message,ENT_QUOTES);
It works for me for both double and single quotes in HTMl.它适用于 HTMl 中的双引号和单引号。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.