如何查看JavaScript/PHP中的两段代码是否等效?
我有一些Ajaxing正在进行,我有两块源代码。第一个是:如何查看JavaScript/PHP中的两段代码是否等效?,php,javascript,html-entities,Php,Javascript,Html Entities,我有一些Ajaxing正在进行,我有两块源代码。第一个是: window.lastSavedContents = "<?php echo htmlentities( $contents ); ?>"; window.lastSavedContents=”“; 第二个是用户在文本编辑器中键入的内容。问题是窗口。lastSavedContents是htmlentities编码的,而第二个块不是 如何检查等价性?您可以找到一种方法来绕过实体编码数据,或者在Javascript中解码wi
window.lastSavedContents = "<?php echo htmlentities( $contents ); ?>";
window.lastSavedContents=”“;
第二个是用户在文本编辑器中键入的内容。问题是窗口。lastSavedContents
是htmlentities
编码的,而第二个块不是
如何检查等价性?您可以找到一种方法来绕过实体编码数据,或者在Javascript中解码
window.lastSavedContents
。这里有一个函数可以帮助您做到这一点:首先,不要使用htmlentities
,但是,它只编码
、&
和“
。这样,您就可以使用
var decoded = encoded.replace(/&/g, '&')
.replace(/</g, '<')
.replace(/"/g, '"')
.replace(/>/g, '>');
var div = document.createElement('div');
div.innerHTML = encoded;
var decoded = div.firstChild.nodeValue;