0

I'm trying to post a YouTube URL along with some other data. The YT URL has 2 parameters and looks something like this:

http://youtube.com/embed/ytid?wmode=transparent&showinfo=0

The full URL would be like this:

http://mysite/proc.php?param1=val1&param2=val2&param3=(the youtube url)

Without the second param (showinfo) it works correctly. But having an ampersand as part of of a parameter value splits the parameter itself, so my query string parameters end up looking like this:

param1: val1
param2: val2
param3: http://youtube.com/embed/ytid?wmode=transparent
showinfo: 0

How should I be handling this?

[EDIT] As helion3 pointed out, the query string needs to be html encoded and it is. The encoded value looks like this:

http://youtube.com/embed/ytid?wmode=transparent&showinfo=0

And the query string parameter ends up like this:

param3: http://youtube.com/embed/ytid?wmode=transparent
amp;showinfo: 0

1 Answer 1

2

You'd need to encode the data for inclusion in a URL.

You tagged this as php, which has urlencode:

urlencode('the&info')

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

4 Comments

The query is being encoded so the param value becomes &showinfo=0, but it still breaks as it's still using an ampersand. I'm going to edit my question to clarify this.
That's not from urlencode... that's from htmlentities. Using urlencode would produce the%26info
What helion3 said. urlencode doesn't transform code into html entitys, it uses the hex representative.
That is it! Thank you, helion3! I knew I'd handled this before.

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.