0

I have to validate an html tag like this:

<object width='400' height='300' data='http://www.youtube.com/v/sqrrzWNKQ' type='application/x-shockwave-flash'><param name='src' value='http://www.youtube.com/v/sqrrzWNKQ'></object>

but the order of the attributes could change or even some of them missing so I have no idea how to do it.

Could anybody enlighten me?

I will validate in Laravel 4.2 (php).

The code:

public function formatYoutubeAMP($content)
{
    $iframe = "/<object width='400' height='300' data='http://www.youtube.com/v/sqrrzWNKQ' type='application/x-shockwave-flash'><param name='src' value='http://www.youtube.com/v/sqrrzWNKQ'></object>";

    // If there is no YT embed the function has no sense.
    if (!preg_match_all($iframe, $content['content'], $matches)) {
        return $content;
    }

    foreach ($matches[0] as $iframeMatch) {
        $iframe = $iframeMatch;
        $content['content'] = str_replace($iframe,
            '<amp-youtube width="400"
                    height="300"
                    layout="responsive"
                    data-videoid="' . $iframe . '"></amp-youtube>'
            , $content['content']
        );
    }

    return $content;
}
Mrquestion
  • 771
  • 1
  • 6
  • 16

0 Answers0