PHP str_pos embed Video

154 Views Asked by At

The problem is, this method work only for one video. And is a text after the link (http://www.youtube.com/watch?v=ID nice video!) then doensn't works.

<?php
                if (strpos($content, 'http://www.youtube.com/watch?v=') !== false) {
                    $content = str_replace("http://www.youtube.com/watch?v=$id", '<object width="' . $width . '" height="' . $height . '"><param name="movie" value="http://www.youtube.com/v/' . $id . '&amp;hl=en_US&amp;fs=1?rel=0"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/' . $id . '&amp;hl=en_US&amp;fs=1?rel=0" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="' . $width . '" height="' . $height . '"></embed></object>', $content);
                } else if (strpos($content, 'https://www.youtube.com/watch?v=') !== false) {
                    $content = str_replace("https://www.youtube.com/watch?v=$id", '<object width="' . $width . '" height="' . $height . '"><param name="movie" value="https://www.youtube.com/v/' . $id . '&amp;hl=en_US&amp;fs=1?rel=0"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="https://www.youtube.com/v/' . $id . '&amp;hl=en_US&amp;fs=1?rel=0" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="' . $width . '" height="' . $height . '"></embed></object>', $content);
                }
    ?>
0

There are 0 best solutions below