Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/281.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 嵌套引号在HTML中不起作用_Javascript_Php_Html_Twitter_Escaping - Fatal编程技术网

Javascript 嵌套引号在HTML中不起作用

Javascript 嵌套引号在HTML中不起作用,javascript,php,html,twitter,escaping,Javascript,Php,Html,Twitter,Escaping,我正在尝试在twitter中使用卡片验证程序()。我的代码在名为content的变量中,所有其他代码都在工作,但twitter元标记除外。我有像\“这样的标签,但当我这样做时,twitter验证程序不会正确显示我的卡 如果我删除\则我的其余代码无法正常工作。是否有办法转义引用,以便twitter卡验证程序接受它并读取元标记 HTML代码: <html> <body> Image link: <input type="text" id="img

我正在尝试在twitter中使用卡片验证程序()。我的代码在名为content的变量中,所有其他代码都在工作,但twitter元标记除外。我有像\“这样的标签,但当我这样做时,twitter验证程序不会正确显示我的卡

如果我删除\则我的其余代码无法正常工作。是否有办法转义引用,以便twitter卡验证程序接受它并读取元标记

HTML代码:

<html>
    <body>
        Image link: <input type="text" id="img">
        Content: <input type="text" id="content">
        <button onclick="makePage()">click</button>
        <script src="makePage.js">
        </script>
        <script>
            var img = document.getElementById("img").value;
            var content = document.getElementById("content").value;   
        </script>
    </body>
</html>

我知道上面写的是“未列入白名单”,但我的网站是列入白名单的(它在主页上工作)。我确信这是由于嵌套的引号造成的。

您需要对查询字符串
内容进行URL编码,因此
xmlhttp.open
应该是:

var content = '<html><head></head><body><meta name="twitter:card" content="summary_large_image"><meta name="twitter:site" content="@nytimes"><meta name="twitter:creator" content="@SarahMaslinNir"><meta name="twitter:title" content="Parade of Fans for Houston’s Funeral"><meta name="twitter:description" content="NEWARK - The guest list and parade of limousines with celebrities emerging from them seemed more suited to a red carpet event in Hollywood or New York than than a gritty stretch of Sussex Avenue near the former site of the James M. Baxter Terrace public housing project here."><meta name="twitter:image" content=""></body></html>';
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET","http://www.michelem.org/ddd.php?content=" + encodeURIComponent(content), true);
xmlhttp.send();
var内容=”;
var xmlhttp=new XMLHttpRequest();
open(“GET”http://www.michelem.org/ddd.php?content=“+encodeURIComponent(content),true);
xmlhttp.send();

使用单引号而不是双引号不是更简单吗?
var content='是的,这确实让它更简单,\'现在自动添加到代码中。但是,当我将URL放入验证程序时,它仍然不起作用。twitter验证程序仍然无法正确读取它,因为\“。我不知道你指的是什么验证器,请添加相关代码。我提到了我指的是Twitter验证器。那么可能是这个,你想放什么url?你能添加你正在使用的代码吗?我已经添加了我的PHP代码。当我添加这个并在var内容周围加上普通引号(“…”)时,它不起作用(我的php代码不执行),但当我加上单引号(“…”)时,它仍然会在所有引号中加上\”。
<?php
    $content = $_GET["content"];
    $file = "" . uniqid() . ".html";
    file_put_contents($file, $content);
    echo $file;
?>
INFO:  Page fetched successfully

INFO:  8 metatags were found

WARN:  Not whitelisted
var content = '<html><head></head><body><meta name="twitter:card" content="summary_large_image"><meta name="twitter:site" content="@nytimes"><meta name="twitter:creator" content="@SarahMaslinNir"><meta name="twitter:title" content="Parade of Fans for Houston’s Funeral"><meta name="twitter:description" content="NEWARK - The guest list and parade of limousines with celebrities emerging from them seemed more suited to a red carpet event in Hollywood or New York than than a gritty stretch of Sussex Avenue near the former site of the James M. Baxter Terrace public housing project here."><meta name="twitter:image" content=""></body></html>';
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET","http://www.michelem.org/ddd.php?content=" + encodeURIComponent(content), true);
xmlhttp.send();