我有一个问题,我搜索了很多,但找不到任何解决方案,所以决定发布一个问题。我有一个网页,它是生成的,需要我将整个附加的网页保存到数据库中。我使用php和mysql.For保存我正在使用的数据:
$(function(){htmldata=$('body').html();});有了这个,我就可以存储整个表单和脚本。但问题是,当我开始从数据库调用值时,html数据显示得很好,但是脚本都搞砸了。
从数据库调用时,我使用的是。
$html = trim(addslashes(htmlspecialchars(
html_entity_decode($_POST['htmldata'], ENT_QUOTES, 'UTF-8'),
ENT_QUOTES, 'UTF-8'
)));对于这个问题,有什么可能的解决方案呢?我想这只适用于没有script.Please帮助的数据。
这就是我的脚本在从数据库调用后的样子。
function test()
{
var formData = form2object('testForm', '.', true,
function(node)
{
if (node.id && node.id.match(/callbackTest/))
{
return { name: node.id, value: node.innerHTML };
}
});就像“被添加”
我的原始脚本
function test()
{
var formData = form2object('testForm', '.', true,
function(node)
{
if (node.id && node.id.match(/callbackTest/))
{
return { name: node.id, value: node.innerHTML };
}
});发布于 2014-03-20 06:35:20
您可以使用以下方法,
//Function to remove slashes
function striptext($Str)
{
//Condition for not empty
if($Str != "")
{
//Condition to check whether the string is not numeric
if(!is_numeric($Str))
return stripslashes(trim($Str));
else
return trim($Str);
}
else
return $Str;
}
//Function to add slashes
function wraptext($Str)
{
//Condition for not empty
if(!empty($Str))
{
//Condition to check whether the string is not numeric
if(!is_numeric($Str))
{
//To check whether the function exists or not
if(function_exists('mysql_real_escape_string'))
return mysql_real_escape_string(htmlspecialchars(stripslashes(trim($Str)), ENT_QUOTES));
else
return addslashes(htmlspecialchars(stripslashes(trim($Str)), ENT_QUOTES));
}
else
return trim($Str);
}
else
return $Str;
}
So while getting post values you can use,
$html = wraptext($_POST['htmldata']);
And while fetching and displaying from database you can use,
echo striptext($your_variable);
And for displaying datas with script tags you can use,
echo striptext(html_entity_decode($your_variable, ENT_QUOTES));https://stackoverflow.com/questions/22524916
复制相似问题