1

I have an array of strings that contain html <object>'s like so:

$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>';

Going through a loop of them, each inside a , I am echoing them out.

The problem is that instead of echoing the DOM elements, the string is being printed like so:

<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>

The quotation marks are used as if I am printing an array, but I have checked that the type of the var is string.

What is going on here?

EDIT:

My string is actually pulled from an API, where I parse some info and use the follow array:

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
)

I pick up [content] and am trying to output the <object> itself.

6
  • 1
    Your sample isn't valid - You'd either need to use single quotes for the string or escape all of the double quotes in the string. Commented Nov 3, 2011 at 12:38
  • Your string variable is being output through htmlspecialchars() or htmlentities(). Commented Nov 3, 2011 at 12:38
  • The sample code doesn't parse, because you wrap it in double quotes and the string includes un-escaped double quotes. Please include your actual code, as this is related to your problem. At a guess, I'd say your actual string is declared like $str = '"<!-- content -->"', and you need to remove the surrounding double quotes. Commented Nov 3, 2011 at 12:39
  • 1
    My string wasn't actually declared like that - please see the edit. Commented Nov 3, 2011 at 12:44
  • 1
    It was virtually the same effect until i realised the quotes were wrong. It was wrong for about 10 minutes. Commented Nov 3, 2011 at 13:07

4 Answers 4

2

using html_entity_decode on the string fixed this.

Sign up to request clarification or add additional context in comments.

1 Comment

why downvote? the string didn't have quote/escape issues, see the edit.
0

Your problem is your use of double quotes :

Try (the string is enclosed with single quotes)

$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>';

Comments

0

You need to escape your strings.

$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>";

Comments

0

Could be a due to you declaring a string with " and that string contains " marks. Try convert the html to have single quotes ' or declare the string with singles quotes or even escape the double quotes in the HTML with a backslash \"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.