Skip to content

Instantly share code, notes, and snippets.

@peteboere
Created March 9, 2011 12:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peteboere/862097 to your computer and use it in GitHub Desktop.
Save peteboere/862097 to your computer and use it in GitHub Desktop.
function for generating swf object html
<?php
function get_swf ( $url, $attributes = array(), $params = array(), $alt_content = null ) {
$attributes = is_array( $attributes ) ? $attributes : array();
$attributes[ 'width' ] = is_numeric( $attributes[ 'width' ] ) ? $attributes[ 'width' ] : 100;
$attributes[ 'height' ] = is_numeric( $attributes[ 'height' ] ) ? $attributes[ 'height' ] : 100;
$attributes_fmt = " %s=\"%s\"";
$attributes_str = '';
foreach ( $attributes as $name => $value ) {
$attributes_str .= sprintf( $attributes_fmt, $name, $value );
}
$params_fmt = "<param name=\"%s\" value=\"%s\" />\n";
$params_str = '';
if ( $params ) {
foreach ( $params as $name => $value ) {
if ( is_array( $value ) ) {
$value = http_build_query( $value );
}
$params_str .= sprintf( $params_fmt, $name, urlencode( $value ) );
}
}
$alt_content = isset( $alt_content ) ? $alt_content :
'<a href="http://www.adobe.com/go/getflashplayer">Get Adobe Flash player</a>';
$ie_movie = sprintf( $params_fmt, 'movie', $url );
return <<<TPL
<!--[if !IE]>-->
<object type="application/x-shockwave-flash" data="$url"$attributes_str>
<!--<![endif]-->
<!--[if IE]>
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"$attributes_str>
$ie_movie<![endif]-->
$params_str$alt_content
</object>\n
TPL;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment