我有一个包含html <object>
的字符串数组,如下所示:
$str = '<object width="600" height="338">
<param name="movie" value="http://www.youtube.com/v/YQSFQUkVUos?version=3&feature=oembed"></param>
<param name="allowFullScreen" value="true"></param>
<param name="allowscriptaccess" value="always"></param>
<embed src="http://www.youtube.com/v/YQSFQUkVUos?version=3&feature=oembed" type="application/x-shockwave-flash" width="600" height="338" allowscriptaccess="always" allowfullscreen="true"></embed>
</object>';
通过它们的循环,每个循环,我回应它们。
问题是,不是回显DOM元素,而是打印字符串,如下所示:
<div>
"<object width="600" height="338">
<param name="movie" value="http://www.youtube.com/v/YQSFQUkVUos?version=3&feature=oembed"></param>
<param name="allowFullScreen" value="true"></param>
<param name="allowscriptaccess" value="always"></param>
<embed src="http://www.youtube.com/v/YQSFQUkVUos?version=3&feature=oembed" type="application/x-shockwave-flash" width="600" height="338" allowscriptaccess="always" allowfullscreen="true"></embed>
</object>"
</div>
引号用作我打印数组,但我检查过var的类型是字符串。
这里发生了什么?
修改
我的字符串实际上是从API中提取的,我解析了一些信息并使用了以下数组:
Array
(
[content] => <object width="600" height="338"><param name="movie" value="http://www.youtube.com/v/YQSFQUkVUos?version=3&feature=oembed"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/YQSFQUkVUos?version=3&feature=oembed" type="application/x-shockwave-flash" width="600" height="338" allowscriptaccess="always" allowfullscreen="true"></embed></object>
[width] => 600
[scrolling] =>
[height] => 338
)
我选择[content]
并尝试输出<object>
本身。
答案 0 :(得分:2)
在字符串上使用html_entity_decode
修复此问题。
答案 1 :(得分:0)
您的问题是您使用双引号:
尝试(字符串用单引号括起来)
$str = '<object width="600" height="338">
<param name="movie" value="http://www.youtube.com/v/YQSFQUkVUos?version=3&feature=oembed"></param>
<param name="allowFullScreen" value="true"></param>
<param name="allowscriptaccess" value="always"></param>
<embed src="http://www.youtube.com/v/YQSFQUkVUos?version=3&feature=oembed" type="application/x-shockwave-flash" width="600" height="338" allowscriptaccess="always" allowfullscreen="true"></embed>
</object>';
答案 2 :(得分:0)
你需要逃避你的字符串。
$str = "<object width=\"600\" height=\"338\">
<param name=\"movie\" value=\"http://www.youtube.com/v/YQSFQUkVUos?version=3&feature=oembed\"></param>
<param name=\"allowFullScreen\" value=\"true\"></param>
<param name=\"allowscriptaccess\" value=\"always\"></param>
<embed src=\"http://www.youtube.com/v/YQSFQUkVUos?version=3&feature=oembed\" type=\"application/x-shockwave-flash\" width=\"600\" height=\"338\" allowscriptaccess=\"always\" allowfullscreen=\"true\"></embed>
</object>";
答案 3 :(得分:0)
可能是因为您声明了一个字符串,其中“和该字符串包含”标记。尝试将html转换为单引号'或使用单引号声明字符串,甚至使用反斜杠转义HTML中的双引号\“