我正在使用php on_start和ob_get_contents来回显html并存储在变量中。但是,当我json编码并检查输出时,它不会输出整个字符串。任何人都可以帮助指出我做错了什么
ob_start();
echo'<a href=\"javascript:pixlr.edit({image:\"http://mywebite.com/uploads/$photo\", title:\" $photoFileNameProper\", service:\"express\", exit:\"http://mywebsite.com/home\", method:\"get\", locktarget: \"true\", target:\"http://mywebsite.com/plixr.php\", locktitle :\"true\"});\" id=\"uploadedPhoto\" title=\"click to enhance photo\"><img src=\"images/editphotohover.png\"/></a>\"';
$photo = ob_get_contents();
ob_end_clean();
我只获得结束锚标记 在json编码输出
答案 0 :(得分:1)
此处无需转义双引号
echo'<a href=\"javascri...
写下这个:
echo'<a href="javascri...
在single quotes中保留双引号!
此外,请注意escaping within single quotes无效:
"\t"
呈现为TABULATOR角色'\t'
呈现为\t
PHP documentation说明了这一点:
因此,这段代码怎么样:
echo'<a href="javascript:pixlr.edit(
{ image: \'http://mywebite.com/uploads/$photo\',
title: \'' . $photoFileNameProper . '\',
service: \'express\',
exit:\'http://mywebsite.com/home\',
method: \'get\',
locktarget: \'true\',
target: \'http://mywebsite.com/plixr.php\',
locktitle: \'true\'
});"
id = "uploadedPhoto"
title = "click to enhance photo">
<img src="images/editphotohover.png"/>
</a>'
;