1

I've got my JS function

<html>
  <head>
    <script>
      function createYoutubeEmbedLink(link){
          return link.replace("http://www.youtube.com/watch?v=",
                                  "http://www.youtube.com/embed/");
        }
    </script>
  </head>

And I'm trying to get it to work with my query what I'm getting from the database

            while($songs = mysql_fetch_array($data))
        {
            Print "<b>Name (id): </b>" .$songs['id'] . "</br>";
            Print "<b>Url: </b>" .$songs['url'] . "</br>";
            Print "</br>";
        }
    ?>

This will display normal Youtube URLs but I'm trying to add the JS function to it so it would convert it to Youtube Embed video. Where should i put the JS function exactly?

7
  • where are you actually calling the video. In any <a> tags? Commented Oct 25, 2013 at 10:32
  • 1
    Atm I'm only calling the URL. With this Print "<b>Url: </b>" .$songs['url'] . "</br>";. It's in string format atm. And now i see a problem already. But yeah, link can be changed to string. But the main problem atm is how to modify the url/string. Commented Oct 25, 2013 at 10:35
  • 1
    Modified my Print URL line: Print "<b>Url: </b> <a href=" .$songs['url'] . ">" .$songs['url'] . "</a></br>"; Commented Oct 25, 2013 at 10:38
  • 1
    I don't want to play the embedded video on clicking the url. I don't want an onclick function for it. I would like that the URLs would be converted on load. The embedded code i understand i know how to go on forward after when normal youtube links have been converted to embed URL-s. But i don't understand how i can load my function to do it for the links. Commented Oct 25, 2013 at 10:52
  • 1
    Ok found a solution. Removed the JS totally. Used str_replace instead Print "<b>Url: </b>" .str_replace('youtube.com/watch?v=','http://www.youtube.com/embed', $songs['url']). "</br>"; Commented Oct 25, 2013 at 11:57

1 Answer 1

1

Ok found a solution. Removed the JS totally. Used str_replace instead Print " Url: " .str_replace('youtube.com/watch?v=','http://www.youtube.com/embed/ …;, $songs['url']). "";

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

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.