DOMDocument
FTW!
<?php
define("EMBED_WIDTH", 352);
define("EMBED_HEIGHT", 244);
$html = <<<HTML
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<embed width="425" height="344" type="application/x-shockwave-flash"
pluginspage="http://www.macromedia.com/go/getflashplayer" src="http://www.youtube.com/somevid"></embed>
</body>
</html>
HTML;
$document = new DOMDocument();
$document->loadHTML($html);
$embeds = $document->getElementsByTagName("embed");
$pattern = <<<REGEXP
|
(https?:\/\/)? # May contain http:// or https://
(www\.)? # May contain www.
youtube\.com # Must contain youtube.com
|xis
REGEXP;
foreach ($embeds as $embed) {
if (preg_match($pattern, $embed->getAttribute("src"))) {
$embed->setAttribute("width", EMBED_WIDTH);
$embed->setAttribute("height", EMBED_HEIGHT);
}
}
echo $document->saveHTML();