我需要更新MySQL数据库中的一些字段。这些字段包含PHP和html代码。我知道这很危险。然而,该应用程序是在内部网上运行的,因此我不想打扰这个讨论。
我的问题是,这似乎是不可能的(对我来说)得到数据库中的代码。部分字符串被截断。我的部分代码(其中出现了问题)如下:
$sql = ("UPDATE `database`.`table` SET `code` = '<iframe width='100%' height='100%' src='http://URL?rel=0&autoplay=1' frameborder='0' allowfullscreen></iframe>') WHERE `table`.`id` =4 LIMIT 1 ;");
问题从第一个'iframe'的第一个'<'开始。在运行它时,它背后的所有内容都不会被解释。当我用一个单词替换代码时,即。'test',代码被正确解释并保存良好。
非常感谢你帮我解决这个问题。
Rob
尝试转义HTML代码中的撇号
$sql = ("UPDATE `database`.`table` SET `code` = '<iframe width=''100%'' height=''100%'' src=''http://URL?rel=0&autoplay=1'' frameborder=''0'' allowfullscreen></iframe>') WHERE `table`.`id` =4 LIMIT 1 ;";
或者更简单一点:
$sql = ("UPDATE `database`.`table` SET `code` = '"<iframe width='100%' height='100%' src='http://URL?rel=0&autoplay=1' frameborder='0' allowfullscreen></iframe>'") WHERE `table`.`id` =4 LIMIT 1 ;";
同样,括号看起来是错误的:
$sql = "UPDATE `database`.`table` SET `code` = '"<iframe width='100%' height='100%' src='http://URL?rel=0&autoplay=1' frameborder='0' allowfullscreen></iframe>'" WHERE `table`.`id` =4 LIMIT 1 ;";
使用function htmlentities()
$orig = "I'll '"walk'" the <b>dog</b> now"
$a = htmlentities($orig);
echo $a; // I'll "walk" the <b>dog</b> now;
和编码()
$b = html_entity_decode($a);
echo $b; // I'll "walk" the <b>dog</b> now