1

I have a url: http://domain.tld/123456789abc.html

My goal is to create an embed code like this:

<iframe src="http://domain.tld/embed-123456789abc-620x360.html" frameborder="0" marginwidth="0" marginheight="0" scrolling="no" width="620" height="360"></iframe>

But instead of gave me this:

<iframe src="http://domain.tld/embed-123456789abc.html-620x360.html" frameborder="0" marginwidth="0" marginheight="0" scrolling="no" width="620" height="360"></iframe>

Notice the ".html" included above (123456789abc.html-620x360)?. How can create the code without the ".html" from the source url?

This is the code being used.

elseif (substr_count($link,"domain")){
        $video_id = explode("/",$link);
        if (isset($video_id[count($video_id)-1])){
            $video_id = $video_id[count($video_id)-1];
            $embed = '<IFRAME SRC="http://domain.tld/embed-'.$video_id.'-'.$width.'x'.$height.'.html" frameborder="0" marginwidth="0" marginheight="0" scrolling="no" width="'.$width.'" height="'.$height.'"></iframe>';
        }

Appreciate the help. Thank you.

Astronyu
  • 61
  • 2
  • 4
  • Possible duplicate of [How to remove extension from string (only real extension!)](http://stackoverflow.com/questions/2395882/how-to-remove-extension-from-string-only-real-extension) – 3ocene Oct 13 '16 at 01:27

2 Answers2

0

You need to 'clean' $video_id because the ".html" should be contained into the array component you are retrieving.

So instead of

$video_id = $video_id[count($video_id)-1];

try something like this:

$video_id = str_replace('.html', '', $video_id[count($video_id)-1]);

Pep Lainez
  • 949
  • 7
  • 12
0

It might be easier to use a regex to match the last part of your original link, already excluding the .html:

elseif (substr_count($link,"domain")) {
    $embed = preg_replace(
        '#.+/([^/]+).html$#',
        '<iframe src="http://domain.tld/embed-$1-'
            . $width . 'x' . $height . '.html"'
            . 'frameborder="0" marginwidth="0" marginheight="0" scrolling="no"'
            . 'width="' . $width . '" height="' . $height . '"></iframe>',
        $link
    );
}
sidyll
  • 57,726
  • 14
  • 108
  • 151