0

This line of code works fine:

<iframe width="560" height="315" src="https://www.youtube.com/embed/0AWIAxqKeNY" allowfullscreen></iframe>

However, if I let the user/admin specify a YouTube link to be embedded in the webpage, it shows an empty box where the YouTube video should be. This is the code I'm using currently:

<iframe width="560" height="315" src="<?php echo $url; ?>" allowfullscreen></iframe>

For testing purposes, the $url = "https://www.youtube.com/embed/0AWIAxqKeNY" (same as the link above) and it is still not showing the video on the page.

4
  • What does the page source show? Commented Oct 14, 2017 at 0:41
  • Have you tried using single quotes in the url variable? Commented Oct 14, 2017 at 0:57
  • Also, I don't see what's stopping you from echoing the whole iframe element with php. That might make it easier to manipulate. Commented Oct 14, 2017 at 1:09
  • have you tried <?php echo '<iframe ... scr="'.$url.'"' ?> ? Commented Oct 14, 2017 at 1:30

2 Answers 2

2

maybe you can try this :

<?php
    $url = "https://www.youtube.com/embed/0AWIAxqKeNY";
    echo "<iframe width='560' height='315' src='".$url."' allowfullscreen></iframe>";
?>
Sign up to request clarification or add additional context in comments.

Comments

1

Can you share the page source code? This should quickly tell us exactly what's wrong.

The format of the value of $url could get altered at multiple points during its journey from data source to HTML. Sometimes forward slashes get escaped. We would be able to see this information in the page source code.

To get the page source code, right click somewhere on the page, right click, and choose "View Source Code". Then find where your <iframe> tag is and see what is being rendered. Then, the simplest way to fix it would be to edit the <?php echo $url; ?> code to reformat the data being outputted so that it'll load the embed properly.

1 Comment

It turns out the variable name was $urls and not $url and I simply couldn't see it. However, checking the page source like this answer suggested ended up guiding me to find the problem (new to web coding and didn't think of doing this prior). Thank you. At this point I'm unsure if I should delete this question from stack overflow since it was a silly mistake or keep it as other may need the "page source" suggestion as well.

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.