我有一个远程网页,我使用CURL和DOMDocument来检索图像的src属性。
我使用以下代码,在PHP echo
中混合JS<?php
$toEcho = "";
$toEcho .= // some stuff here...
$toEcho.="
<script>
//I create the object
var img = new Image();
//I set the source with the PHP variable : I get an error because of unexpected token ":"
img.src = $imgsrc;
</script>"
echo $toEcho;
?>
我检查了源代码,它是有效的,并且在我的浏览器中正确显示。
这是怎么来的?
像这样设置源代码:
img.src = '$imgsrc';