Re: How to take video embed codes and change all their widths/heights?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Jan 15, 2008 5:25 PM, Rob Gould <GouldIMG@xxxxxxx> wrote:
> Can anytime give me some insights on how to write a PHP script that
> could accept any of the below strings below and edit the strings to
> change their width and height settings dynamically?
>
> For instance, if I want all embedded videos to have a width of 320,
> and a height of 240, using PHP's string manipulation commands, what's
> the best way to "hone in" on width="425" and change it to
> width="320"?  (In all cases in each string)

    Basic variable manipulation.

<?
$width = "320";
$embed_code =<<<EOL
<object width="$width" height="$height"
classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"><param
name="movie" value="http://www2.funnyordie.com/public/flash/fodplayer.swf";
/><param name="flashvars" value="key=5468" /><param
name="allowfullscreen" value="true" /><embed width="$width"
height="$height" flashvars="key=5468" allowfullscreen="true"
quality="high" src="http://www2.funnyordie.com/public/flash/fodplayer.swf";
type="application/x-shockwave-flash"></embed></object><noscript><a
href="http://www.funnyordie.com/videos/5468";>Cars</a> on <a
href="http://www.funnyordie.com";>FunnyOrDie.com</a></noscript>
EOL;
?>

    Another way of doing it is with a simple regexp and preg_replace(), like so:


<?
$embed_code =<<<EOL
<object width="464" height="388"
classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"><param
name="movie" value="http://www2.funnyordie.com/public/flash/fodplayer.swf";
/><param name="flashvars" value="key=5468" /><param
name="allowfullscreen" value="true" /><embed width="464" height="388"
flashvars="key=5468" allowfullscreen="true" quality="high"
src="http://www2.funnyordie.com/public/flash/fodplayer.swf";
type="application/x-shockwave-flash"></embed></object><noscript><a
href="http://www.funnyordie.com/videos/5468";>Cars</a> on <a
href="http://www.funnyordie.com";>FunnyOrDie.com</a></noscript>
EOL;

$height = "111";
$width = "222";

$embed_code = preg_replace('/height="([0-9]*)"/U','height="'.$height.'"',preg_replace('/width="([0-9]*)"/U','width="'.$width.'"',$embed_code));

echo $embed_code."\n";
?>


-- 
</Dan>

Daniel P. Brown
Senior Unix Geek and #1 Rated "Year's Coolest Guy" By Self Since
Nineteen-Seventy-[mumble].

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux