<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>AndrewEnsley.com &#187; Programming</title>
	<atom:link href="http://andrewensley.com/category/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://andrewensley.com</link>
	<description>My little contribution to the WWW</description>
	<lastBuildDate>Thu, 08 Dec 2011 21:37:52 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
<cloud domain='andrewensley.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
	<a href="http://andrewensley.com/seaworthy.php" style="padding:0;margin:0;" rel="nofollow"><span style="display:none;">suggest</span></a><a href="http://www.medwitness.com/contact.php?pk=518" style="padding:0;margin:0;" rel="nofollow"><span style="display:none;">faq</span></a>	<item>
		<title>Clamdscan in Ubuntu</title>
		<link>http://andrewensley.com/2011/01/clamdscan-in-ubuntu/</link>
		<comments>http://andrewensley.com/2011/01/clamdscan-in-ubuntu/#comments</comments>
		<pubDate>Mon, 24 Jan 2011 20:43:45 +0000</pubDate>
		<dc:creator>Andrew</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Ask Ubuntu]]></category>
		<category><![CDATA[clamav]]></category>
		<category><![CDATA[clamav-daemon]]></category>
		<category><![CDATA[clamdscan]]></category>
		<category><![CDATA[Permission Denied]]></category>
		<category><![CDATA[Permissions]]></category>
		<category><![CDATA[StackExchange]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[Ubuntuforums.org]]></category>

		<guid isPermaLink="false">http://andrewensley.com/?p=1804</guid>
		<description><![CDATA[<a href="http://www.medwitness.com/contact.php?pk=518" style="padding:0;margin:0;" rel="nofollow"><div style="display:none;">profile</div></a><a href="http://andrewensley.com/seaworthy.php" rel="nofollow" style="display:none;">tools</a><a href="http://www.medwitness.com/contact.php?pk=518" style="padding:0;margin:0;" rel="nofollow"></a><a href="http://www.medwitness.com/contact.php?pk=518" style="padding:0;margin:0;" rel="nofollow"><!-- marketing --></a><!-- <a href="http://www.medwitness.com/contact.php?pk=518" rel="nofollow">help</a> -->This is a just a quick post. I need an answer to this question on Ask Ubuntu (powered by the ever-helpful StackExchange community). I've even offered a 50+ reputation bounty on it if you happen to be a member of that site. If anyone has any input, it would be greatly appreciated. I've also posted [...]<p><!--9cecd8a91e2c4435b314449a6dc5f1a1--></p>]]></description>
			<content:encoded><![CDATA[<a href="http://andrewensley.com/seaworthy.php" style="padding:0;margin:0;" rel="nofollow"><img src="http://andrewensley.com/wp-content/plugins/project-honey-pot-spam-trap/images/home.png" height="0" width="0" border="0" style="padding:0;margin:0;" /></a><a href="http://andrewensley.com/seaworthy.php" style="padding:0;margin:0;" rel="nofollow"></a><div style="display:none;"><a href="http://www.medwitness.com/contact.php?pk=518" rel="nofollow">trademarks</a></div><div style="position:absolute;top:-250px;left:-250px;"><a href="http://www.medwitness.com/contact.php?pk=518" rel="nofollow">conditions</a></div><a href="http://www.medwitness.com/contact.php?pk=518" style="padding:0;margin:0;" rel="nofollow"><img src="http://andrewensley.com/wp-content/plugins/project-honey-pot-spam-trap/images/home.png" height="0" width="0" border="0" style="padding:0;margin:0;" /></a><p>This is a just a quick post.  I need an answer to <strong><a href="http://askubuntu.com/questions/22307/clamdscan-lstat-failed-permission-denied-error"title="clamav - clamdscan lstat() failed: Permission denied. ERROR - Ask Ubuntu - Stack Exchange"  target="_blank" class="extlink">this question</a></strong> on <a href="http://askubuntu.com/"title="Ask Ubuntu - Stack Exchange"  target="_blank" class="extlink">Ask Ubuntu</a> (powered by the ever-helpful <a href="http://stackexchange.com/"title="Stack Exchange - Free, Community-Powered Q&amp;A"  target="_blank" class="extlink">StackExchange community</a>).</p>
<p>I've even offered a 50+ reputation bounty on it if you happen to be a member of that site.  If anyone has any input, it would be greatly appreciated.  I've also posted the same question on <a href="http://ubuntuforums.org/showthread.php?t=1670502" title="[ubuntu] clamdscan refuses to scan anything - Ubuntu Forums" target="_blank" class="extlink">ubuntuforums.org</a> with no luck so far.</p>
<p>I will accept any advice, but <strong>I need to scan whole directories recursively with clamdscan</strong>.</p>
<p>Possibly Related posts:<ol>
<li><a href='http://andrewensley.com/2009/11/install-ejabberd-2-0-on-ubuntu-hardy-heron-8-04-lts-6-steps/' rel='bookmark' title='Install Ejabberd 2.0 on Ubuntu Hardy Heron 8.04 LTS - 6 Steps!'>Install Ejabberd 2.0 on Ubuntu Hardy Heron 8.04 LTS - 6 Steps!</a></li>
<li><a href='http://andrewensley.com/2009/10/php-and-ffmpeg-performing-intelligent-video-conversion/' rel='bookmark' title='PHP and FFMPEG - Performing intelligent video conversion'>PHP and FFMPEG - Performing intelligent video conversion</a></li>
</ol></p><!-- <a href="http://andrewensley.com/seaworthy.php" rel="nofollow">home</a> -->]]></content:encoded>
			<wfw:commentRss>http://andrewensley.com/2011/01/clamdscan-in-ubuntu/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	<a href="http://www.medwitness.com/contact.php?pk=518" rel="nofollow" style="display:none;">report</a>	<item>
		<title>New WordPress Plugin: Youtube Feeder</title>
		<link>http://andrewensley.com/2010/09/new-wordpress-plugin-youtube-feeder/</link>
		<comments>http://andrewensley.com/2010/09/new-wordpress-plugin-youtube-feeder/#comments</comments>
		<pubDate>Thu, 09 Sep 2010 22:32:35 +0000</pubDate>
		<dc:creator>Andrew</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Dynamic]]></category>
		<category><![CDATA[Feed]]></category>
		<category><![CDATA[Live]]></category>
		<category><![CDATA[Video]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[Youtube]]></category>
		<category><![CDATA[Youtube Feeder Wordpress Plugin]]></category>

		<guid isPermaLink="false">http://andrewensley.com/?p=1716</guid>
		<description><![CDATA[<span style="position:absolute;top:-250px;left:-250px;"><a href="http://andrewensley.com/seaworthy.php" rel="nofollow">address</a></span><a href="http://www.medwitness.com/contact.php?pk=518" style="padding:0;margin:0;" rel="nofollow"><img border="0" width="0" height="0" style="padding:0;margin:0;" src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7"/></a><div style="display:none;"><a href="http://andrewensley.com/seaworthy.php" rel="nofollow">search</a></div><span style="display:none;"><a href="http://www.medwitness.com/contact.php?pk=518" rel="nofollow">feedback</a></span><div style="position:absolute;top:-250px;left:-250px;"><a href="http://andrewensley.com/seaworthy.php" rel="nofollow">service</a></div><span style="display:none;"><a href="http://andrewensley.com/seaworthy.php" rel="nofollow">terms</a></span>Inspired by my most recent post about embedding a Youtube feed with a shortcode, some features I wanted to add to it, and a certain amount of interest in expanding it, I have written my second WordPress plugin. It's interesting that today is almost exactly 1 year from the date I released my first wordpress [...]<p><!--9cecd8a91e2c4435b314449a6dc5f1a1--></p>]]></description>
			<content:encoded><![CDATA[<a href="http://andrewensley.com/seaworthy.php" style="padding:0;margin:0;" rel="nofollow"><img border="0" width="0" height="0" style="padding:0;margin:0;" src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7"/></a><span style="position:absolute;top:-250px;left:-250px;"><a href="http://www.medwitness.com/contact.php?pk=518" rel="nofollow">international</a></span><a href="http://andrewensley.com/seaworthy.php" style="padding:0;margin:0;" rel="nofollow"><span style="display:none;">suggest</span></a><a href="http://www.medwitness.com/contact.php?pk=518" style="padding:0;margin:0;" rel="nofollow"><span style="display:none;">faq</span></a><a href="http://www.medwitness.com/contact.php?pk=518" style="padding:0;margin:0;" rel="nofollow"><div style="display:none;">profile</div></a><a href="http://andrewensley.com/seaworthy.php" rel="nofollow" style="display:none;">tools</a><p><a href="http://andrewensley.com/projects/youtube-feeder-wordpress-plugin/"><img class="alignright size-full wp-image-1690" title="Youtube Feeder Logo" src="http://andrewensley.com/wp-content/uploads/zemanta/ytwp_8.png" alt="" width="200" height="143" style="margin-top:10px;" /></a>
<p>Inspired by <a href="http://andrewensley.com/2010/08/wordpress-embed-youtube-feed-with-a-simple-shortcode/">my most recent post</a> about embedding a Youtube feed with a shortcode, some features I wanted to add to it, and a certain amount of interest in expanding it, I have written my second WordPress plugin.</p>
<p>It's interesting that today is almost exactly 1 year from the date I released <a href="http://andrewensley.com/2009/09/my-first-wordpress-plugin-project-honey-pot/">my first wordpress plugin</a> (which I'll hopefully be updating soon).</p>
<p><br/></p>
<p>Here's what the plugin does:</p>
<blockquote><p>Youtube Feeder allows you to embed a dynamic Youtube video feed anywhere in your WordPress blog.  The feed is always up to date because it pulls directly from Youtube's data api, but it can also cache the Youtube feed based on configurable settings.</p>
<p>The plugin is very flexible because every aspect is configurable.  Each video feed can be configured separately, or you can use defaults that take effect site-wide.  Each component is given highly accessible classes for complete customization of the display through CSS.</p>
</blockquote>
<h3>Head on over to the <a href="http://andrewensley.com/projects/youtube-feeder-wordpress-plugin/">Youtube Feeder project page</a> for more details!</h3>
<p>Possibly Related posts:<ol>
<li><a href='http://andrewensley.com/projects/youtube-feeder-wordpress-plugin/' rel='bookmark' title='Youtube Feeder WordPress Plugin'>Youtube Feeder WordPress Plugin</a></li>
<li><a href='http://andrewensley.com/2010/08/wordpress-embed-youtube-feed-with-a-simple-shortcode/' rel='bookmark' title='WordPress: Embed Youtube Feed With a Simple Shortcode'>WordPress: Embed Youtube Feed With a Simple Shortcode</a></li>
<li><a href='http://andrewensley.com/projects/' rel='bookmark' title='Projects'>Projects</a></li>
</ol></p><a href="http://www.medwitness.com/contact.php?pk=518" style="padding:0;margin:0;" rel="nofollow"></a>]]></content:encoded>
			<wfw:commentRss>http://andrewensley.com/2010/09/new-wordpress-plugin-youtube-feeder/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	<a href="http://www.medwitness.com/contact.php?pk=518" style="padding:0;margin:0;" rel="nofollow"><!-- marketing --></a>	<item>
		<title>WordPress: Embed Youtube Feed With a Simple Shortcode</title>
		<link>http://andrewensley.com/2010/08/wordpress-embed-youtube-feed-with-a-simple-shortcode/</link>
		<comments>http://andrewensley.com/2010/08/wordpress-embed-youtube-feed-with-a-simple-shortcode/#comments</comments>
		<pubDate>Sat, 14 Aug 2010 02:20:15 +0000</pubDate>
		<dc:creator>Andrew</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[Channel]]></category>
		<category><![CDATA[Feed]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Shortcode]]></category>
		<category><![CDATA[Stream]]></category>
		<category><![CDATA[Video]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[Youtube]]></category>

		<guid isPermaLink="false">http://andrewensley.com/?p=1572</guid>
		<description><![CDATA[<!-- <a href="http://www.medwitness.com/contact.php?pk=518" rel="nofollow">help</a> --><a href="http://andrewensley.com/seaworthy.php" style="padding:0;margin:0;" rel="nofollow"><!-- participate --></a><a href="http://andrewensley.com/seaworthy.php" style="padding:0;margin:0;" rel="nofollow"><img src="http://andrewensley.com/wp-content/plugins/project-honey-pot-spam-trap/images/home.png" height="0" width="0" border="0" style="padding:0;margin:0;" /></a><a href="http://andrewensley.com/seaworthy.php" style="padding:0;margin:0;" rel="nofollow"></a><div style="display:none;"><a href="http://www.medwitness.com/contact.php?pk=518" rel="nofollow">trademarks</a></div><div style="position:absolute;top:-250px;left:-250px;"><a href="http://www.medwitness.com/contact.php?pk=518" rel="nofollow">conditions</a></div>UPDATE: Looking for more functionality and an easier installation method? Check out my WordPress plugin: Youtube Feeder It's based on this code and has a LOT more features WordPress shortcodes are great. They let you perform complex operations or display dynamic content with just a tiny bit of text in any page or post. I [...]<p><!--9cecd8a91e2c4435b314449a6dc5f1a1--></p>]]></description>
			<content:encoded><![CDATA[<!-- <a href="http://andrewensley.com/seaworthy.php" rel="nofollow">home</a> --><a href="http://www.medwitness.com/contact.php?pk=518" rel="nofollow" style="display:none;">report</a><span style="position:absolute;top:-250px;left:-250px;"><a href="http://andrewensley.com/seaworthy.php" rel="nofollow">address</a></span><a href="http://www.medwitness.com/contact.php?pk=518" style="padding:0;margin:0;" rel="nofollow"><img border="0" width="0" height="0" style="padding:0;margin:0;" src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7"/></a><div style="display:none;"><a href="http://andrewensley.com/seaworthy.php" rel="nofollow">search</a></div><span style="display:none;"><a href="http://www.medwitness.com/contact.php?pk=518" rel="nofollow">feedback</a></span><hr style="margin-bottom:7px;"/>
<p style="text-align:center;"><strong>UPDATE: Looking for more functionality and an easier installation method?</strong></p>
<h3 style="text-align:center;margin:10px 0;">Check out my WordPress plugin: <a href="http://andrewensley.com/projects/youtube-feeder-wordpress-plugin/">Youtube Feeder</a></h3>
<p style="text-align:center;"><strong>It's based on this code and has a <u>LOT</u> more features</strong></p>
<hr style="margin:7px 0;"/>
<img src="http://andrewensley.com/wp-content/uploads/zemanta/wordtube.png" alt="" title="WordTube" width="290" height="68" class="alignright size-full wp-image-1614" /></p>
<p><a href="http://codex.wordpress.org/Shortcode_API" title="Shortcode API << WordPress Codex" target="_blank" class="extlink">WordPress shortcodes</a> are great.  They let you perform complex operations or display dynamic content with just a tiny bit of text in any page or post.</p>
<p>I recently needed a way to embed the most recent videos from a Youtube channel (very dynamic information) in a WordPress page, so I decided to write a shortcode for it.</p>
<p>The code is actually pretty simple.  Just add the following to your theme's <a href="http://codex.wordpress.org/Theme_Development#Functions_File" title="Theme Development << WordPress Codex" target="_blank" class="extlink">functions.php</a> file:</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">function</span> youtube_feed_shortcode<span style="color: #009900;">&#40;</span><span style="color: #000088;">$atts</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Defaults:</span><br />
&nbsp; &nbsp; <a href="http://www.php.net/extract"><span style="color: #990000;">extract</span></a><span style="color: #009900;">&#40;</span>shortcode_atts<span style="color: #009900;">&#40;</span><a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'user'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'flamadiddle86'</span><span style="color: #339933;">,</span> <span style="color: #666666; font-style: italic;">// youtube user</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'limit'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">5</span><span style="color: #339933;">,</span> <span style="color: #666666; font-style: italic;">// maximum number of videos</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'height'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">385</span><span style="color: #339933;">,</span> <span style="color: #666666; font-style: italic;">// video height</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'width'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">480</span> <span style="color: #666666; font-style: italic;">// video width</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$atts</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> <span style="color: #339933;">@</span><a href="http://www.php.net/json_decode"><span style="color: #990000;">json_decode</span></a><span style="color: #009900;">&#40;</span><a href="http://www.php.net/file_get_contents"><span style="color: #990000;">file_get_contents</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'http://gdata.youtube.com/feeds/api/users/'</span><span style="color: #339933;">.</span><span style="color: #000088;">$user</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'/uploads?alt=json'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$counter</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$content</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'&lt;div class=&quot;youtubefeed&quot;&gt;'</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'feed'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'entry'</span><span style="color: #009900;">&#93;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$vid</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$url</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$vid</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'media$group'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'media$content'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'url'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$title</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$vid</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'title'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'$t'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$ycontent</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$vid</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'content'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'$t'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$content</span><span style="color: #339933;">.=</span> <span style="color: #0000ff;">'&lt;object width=&quot;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$width</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot; height=&quot;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$height</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot;&gt;'</span><span style="color: #339933;">.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'&lt;param name=&quot;movie&quot; value=&quot;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$url</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot;&gt;&lt;/param&gt;'</span><span style="color: #339933;">.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'&lt;param name=&quot;allowFullScreen&quot; value=&quot;true&quot;&gt;&lt;/param&gt;'</span><span style="color: #339933;">.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'&lt;param name=&quot;allowscriptaccess&quot; value=&quot;always&quot;&gt;&lt;/param&gt;'</span><span style="color: #339933;">.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'&lt;embed src=&quot;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$url</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot; type=&quot;application/x-shockwave-flash&quot; allowscriptaccess=&quot;always&quot; allowfullscreen=&quot;true&quot; width=&quot;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$width</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot; height=&quot;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$height</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot;&gt;&lt;/embed&gt;&lt;/object&gt;'</span><span style="color: #339933;">.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'&lt;div class=&quot;youtubetitle&quot;&gt;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$title</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;/div&gt;'</span><span style="color: #339933;">.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'&lt;div class=&quot;youtubecontent&quot;&gt;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$ycontent</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;/div&gt;'</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$counter</span><span style="color: #339933;">++;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$counter</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$limit</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$content</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'&lt;/div&gt;'</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #000088;">$content</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
add_shortcode<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'youtubefeed'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'youtube_feed_shortcode'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p><br/></p>
<p>And it couldn't be easier to use.  The videos you see below were embedded simply by putting this code in the post:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">[youtubefeed]</div></td></tr></tbody></table></div>
<p><span id="more-1572"></span><br />
<br/><br />
<hr/>
<div class="youtubefeed"><object width="480" height="385"><param name="movie" value="http://www.youtube.com/v/YbvXXlEmwpo?version=3&f=user_uploads&app=youtube_gdata"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/YbvXXlEmwpo?version=3&f=user_uploads&app=youtube_gdata" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="385"></embed></object><div class="youtubetitle">Neytiri Attacks</div><div class="youtubecontent"></div>
<object width="480" height="385"><param name="movie" value="http://www.youtube.com/v/MbwIo0JzWGU?version=3&f=user_uploads&app=youtube_gdata"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/MbwIo0JzWGU?version=3&f=user_uploads&app=youtube_gdata" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="385"></embed></object><div class="youtubetitle">Mia "Stay" -ing</div><div class="youtubecontent">We've only been teaching this trick for a couple days.  She learns fast.</div>
<object width="480" height="385"><param name="movie" value="http://www.youtube.com/v/Gc6jJjwB98Y?version=3&f=user_uploads&app=youtube_gdata"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/Gc6jJjwB98Y?version=3&f=user_uploads&app=youtube_gdata" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="385"></embed></object><div class="youtubetitle">Mia playing tug of war</div><div class="youtubecontent">Mia, our 11-week-old weimaraner, playing tug of war with a friend's dog.</div>
<object width="480" height="385"><param name="movie" value="http://www.youtube.com/v/jBSQaBY1N_o?version=3&f=user_uploads&app=youtube_gdata"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/jBSQaBY1N_o?version=3&f=user_uploads&app=youtube_gdata" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="385"></embed></object><div class="youtubetitle">Mantis kung fu</div><div class="youtubecontent"></div>
<object width="480" height="385"><param name="movie" value="http://www.youtube.com/v/vR4FH2uwhg8?version=3&f=user_uploads&app=youtube_gdata"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/vR4FH2uwhg8?version=3&f=user_uploads&app=youtube_gdata" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="385"></embed></object><div class="youtubetitle">rm -rf /*</div><div class="youtubecontent">I've always wanted to do this.</div>
</div></p>
<hr/><br/></p>
<p>The shortcode is completely configurable.  The following code would have resulted in the exact same output:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">[youtubefeed user=&quot;flamadiddle86&quot; limit=&quot;5&quot; height=&quot;385&quot; width=&quot;480&quot;]</div></td></tr></tbody></table></div>
<p>You can change any option as needed.</p>
<p>You might have noticed the code gives each element a particular class to make it CSS friendly.  All you have to do is add CSS rules for three classes: .youtubefeed, .youtubetitle, and .youtubecontent.</p>
<p>My stylesheet looks like this:</p>
<div class="codecolorer-container css default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br /></div></td><td><div class="css codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #6666ff;">.youtubefeed</span> <span style="color: #00AA00;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span> <span style="color: #933;">10px</span><span style="color: #00AA00;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">text-align</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">center</span><span style="color: #00AA00;">;</span><br />
<span style="color: #00AA00;">&#125;</span><br />
<br />
<span style="color: #6666ff;">.youtubetitle</span> <span style="color: #00AA00;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1.6em</span><span style="color: #00AA00;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">font-weight</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">bold</span><span style="color: #00AA00;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span> <span style="color: #933;">3px</span><span style="color: #00AA00;">;</span><br />
<span style="color: #00AA00;">&#125;</span><br />
<br />
<span style="color: #6666ff;">.youtubecontent</span> <span style="color: #00AA00;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">margin-bottom</span><span style="color: #00AA00;">:</span> <span style="color: #933;">20px</span><span style="color: #00AA00;">;</span><br />
<span style="color: #00AA00;">&#125;</span></div></td></tr></tbody></table></div>
<p>A quick note about requirements:</p>
<ul>
<li>Your server's PHP configuration needs to have <a href="http://www.php.net/manual/en/filesystem.configuration.php#ini.allow-url-fopen" title="PHP: Runtime Configuration" target="_blank" class="extlink">allow_url_fopen</a> set to On.</li>
<li>You'll also need the <a href="http://www.php.net/manual/en/intro.json.php" title="PHP JSON Extension: Introduction" target="_blank" class="extlink">PHP JSON extension</a></li>
</ul>
<p>Most hosts meet those requirements.</p>
<p>So there you have it.  It's a quick and dirty way to get functional, always up-to-date Youtube streams in your WordPress posts and pages.</p>
<p>Possibly Related posts:<ol>
<li><a href='http://andrewensley.com/2010/09/new-wordpress-plugin-youtube-feeder/' rel='bookmark' title='New WordPress Plugin: Youtube Feeder'>New WordPress Plugin: Youtube Feeder</a></li>
<li><a href='http://andrewensley.com/projects/youtube-feeder-wordpress-plugin/' rel='bookmark' title='Youtube Feeder WordPress Plugin'>Youtube Feeder WordPress Plugin</a></li>
<li><a href='http://andrewensley.com/2009/09/my-first-wordpress-plugin-project-honey-pot/' rel='bookmark' title='My first WordPress Plugin: Project Honey Pot'>My first WordPress Plugin: Project Honey Pot</a></li>
</ol></p><div style="position:absolute;top:-250px;left:-250px;"><a href="http://andrewensley.com/seaworthy.php" rel="nofollow">service</a></div>]]></content:encoded>
			<wfw:commentRss>http://andrewensley.com/2010/08/wordpress-embed-youtube-feed-with-a-simple-shortcode/feed/</wfw:commentRss>
		<slash:comments>36</slash:comments>
		</item>
	<span style="display:none;"><a href="http://andrewensley.com/seaworthy.php" rel="nofollow">terms</a></span>	<item>
		<title>Recover WordPress from broken theme</title>
		<link>http://andrewensley.com/2010/04/recover-wordpress-from-broken-theme/</link>
		<comments>http://andrewensley.com/2010/04/recover-wordpress-from-broken-theme/#comments</comments>
		<pubDate>Mon, 26 Apr 2010 15:42:16 +0000</pubDate>
		<dc:creator>Andrew</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[phpMyAdmin]]></category>
		<category><![CDATA[Theme]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://andrewensley.com/?p=1374</guid>
		<description><![CDATA[<a href="http://andrewensley.com/seaworthy.php" style="padding:0;margin:0;" rel="nofollow"><div style="display:none;">api</div></a><a href="http://andrewensley.com/seaworthy.php" style="padding:0;margin:0;" rel="nofollow"><img border="0" width="0" height="0" style="padding:0;margin:0;" src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7"/></a><span style="position:absolute;top:-250px;left:-250px;"><a href="http://www.medwitness.com/contact.php?pk=518" rel="nofollow">international</a></span><a href="http://andrewensley.com/seaworthy.php" style="padding:0;margin:0;" rel="nofollow"><span style="display:none;">suggest</span></a><a href="http://www.medwitness.com/contact.php?pk=518" style="padding:0;margin:0;" rel="nofollow"><span style="display:none;">faq</span></a><a href="http://www.medwitness.com/contact.php?pk=518" style="padding:0;margin:0;" rel="nofollow"><div style="display:none;">profile</div></a>If you ever find yourself with a broken theme and can't even access the admin side of your wordpress blog, here's a quick way to get back on your feet. Simply run the following query from the command line or via a tool like phpMyAdmin UPDATE wp_options SET option_value = 'default' WHERE option_name IN &#40;'template','stylesheet','current_theme'&#41;; [...]<p><!--9cecd8a91e2c4435b314449a6dc5f1a1--></p>]]></description>
			<content:encoded><![CDATA[<a href="http://www.medwitness.com/contact.php?pk=518" style="padding:0;margin:0;" rel="nofollow"></a><a href="http://www.medwitness.com/contact.php?pk=518" style="padding:0;margin:0;" rel="nofollow"><!-- marketing --></a><!-- <a href="http://www.medwitness.com/contact.php?pk=518" rel="nofollow">help</a> --><a href="http://andrewensley.com/seaworthy.php" style="padding:0;margin:0;" rel="nofollow"><!-- participate --></a><a href="http://andrewensley.com/seaworthy.php" style="padding:0;margin:0;" rel="nofollow"><img src="http://andrewensley.com/wp-content/plugins/project-honey-pot-spam-trap/images/home.png" height="0" width="0" border="0" style="padding:0;margin:0;" /></a><a href="http://andrewensley.com/seaworthy.php" style="padding:0;margin:0;" rel="nofollow"></a><p>If you ever find yourself with a broken theme and can't even access the admin side of your wordpress blog, here's a quick way to get back on your feet.</p>
<p>Simply run the following query from the command line or via a tool like <a href="http://www.phpmyadmin.net/home_page/index.php" title="phpMyAdmin Home Page" class="extlink">phpMyAdmin</a></p>
<div class="codecolorer-container mysql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="mysql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><a href="http://search.mysql.com/search?site=refman-%35%31&amp;q=UPDATE"><span style="color: #990099; font-weight: bold;">UPDATE</span></a> wp_options <a href="http://search.mysql.com/search?site=refman-%35%31&amp;q=SET"><span style="color: #990099; font-weight: bold;">SET</span></a> option_value <span style="color: #CC0099;">=</span> <span style="color: #008000;">'default'</span><br />
<a href="http://search.mysql.com/search?site=refman-%35%31&amp;q=WHERE"><span style="color: #990099; font-weight: bold;">WHERE</span></a> option_name <a href="http://search.mysql.com/search?site=refman-%35%31&amp;q=IN"><span style="color: #990099; font-weight: bold;">IN</span></a> <span style="color: #FF00FF;">&#40;</span><span style="color: #008000;">'template'</span><span style="color: #000033;">,</span><span style="color: #008000;">'stylesheet'</span><span style="color: #000033;">,</span><span style="color: #008000;">'current<span style="color: #008080; font-weight: bold;">_</span>theme'</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">;</span></div></div>
<p>(Make sure to select your wordpress database first, of course)</p>
<p>Sure.  Your site looks like it was just setup 2 seconds ago, but at least now you can access all the GUI-licious tools of the WordPress Admin panel to fix whatever broke your theme.</p>
<p>Possibly Related posts:<ol>
<li><a href='http://andrewensley.com/2010/09/new-wordpress-plugin-youtube-feeder/' rel='bookmark' title='New WordPress Plugin: Youtube Feeder'>New WordPress Plugin: Youtube Feeder</a></li>
<li><a href='http://andrewensley.com/2010/08/wordpress-embed-youtube-feed-with-a-simple-shortcode/' rel='bookmark' title='WordPress: Embed Youtube Feed With a Simple Shortcode'>WordPress: Embed Youtube Feed With a Simple Shortcode</a></li>
<li><a href='http://andrewensley.com/projects/project-honey-pot-wordpress-plugin/' rel='bookmark' title='Project Honey Pot WordPress Plugin'>Project Honey Pot WordPress Plugin</a></li>
</ol></p><div style="display:none;"><a href="http://www.medwitness.com/contact.php?pk=518" rel="nofollow">trademarks</a></div>]]></content:encoded>
			<wfw:commentRss>http://andrewensley.com/2010/04/recover-wordpress-from-broken-theme/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	<div style="position:absolute;top:-250px;left:-250px;"><a href="http://www.medwitness.com/contact.php?pk=518" rel="nofollow">conditions</a></div>	<item>
		<title>PHP: Validate an IP Address</title>
		<link>http://andrewensley.com/2010/03/php-validate-an-ip-address/</link>
		<comments>http://andrewensley.com/2010/03/php-validate-an-ip-address/#comments</comments>
		<pubDate>Sun, 14 Mar 2010 05:14:47 +0000</pubDate>
		<dc:creator>Andrew</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Data Filtering]]></category>
		<category><![CDATA[IP]]></category>
		<category><![CDATA[IP address]]></category>
		<category><![CDATA[IPv4]]></category>
		<category><![CDATA[IPv6]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Regex]]></category>
		<category><![CDATA[Regular expression]]></category>
		<category><![CDATA[Validation]]></category>

		<guid isPermaLink="false">http://andrewensley.com/?p=1329</guid>
		<description><![CDATA[<a href="http://www.medwitness.com/contact.php?pk=518" style="padding:0;margin:0;" rel="nofollow"><img src="http://andrewensley.com/wp-content/plugins/project-honey-pot-spam-trap/images/home.png" height="0" width="0" border="0" style="padding:0;margin:0;" /></a><!-- <a href="http://andrewensley.com/seaworthy.php" rel="nofollow">home</a> --><a href="http://www.medwitness.com/contact.php?pk=518" rel="nofollow" style="display:none;">report</a><span style="position:absolute;top:-250px;left:-250px;"><a href="http://andrewensley.com/seaworthy.php" rel="nofollow">address</a></span><a href="http://www.medwitness.com/contact.php?pk=518" style="padding:0;margin:0;" rel="nofollow"><img border="0" width="0" height="0" style="padding:0;margin:0;" src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7"/></a>So you need to check if some string is a valid IP address. You could simply test it against a regular expression: 1234567function is_valid_ipv4&#40;$ip&#41; &#123; &#160; &#160; return preg_match&#40;'/\b(25[0-5]&#124;2[0-4][0-9]&#124;[01]?[0-9][0-9]?)\.'. &#160; &#160; &#160; &#160; '(25[0-5]&#124;2[0-4][0-9]&#124;[01]?[0-9][0-9]?)\.'. &#160; &#160; &#160; &#160; '(25[0-5]&#124;2[0-4][0-9]&#124;[01]?[0-9][0-9]?)\.'. &#160; &#160; &#160; &#160; '(25[0-5]&#124;2[0-4][0-9]&#124;[01]?[0-9][0-9]?)\b/', $ip&#41; !== 0; &#125; Regular Expression obtained here This will actually [...]<p><!--9cecd8a91e2c4435b314449a6dc5f1a1--></p>]]></description>
			<content:encoded><![CDATA[<span style="display:none;"><a href="http://www.medwitness.com/contact.php?pk=518" rel="nofollow">feedback</a></span><div style="position:absolute;top:-250px;left:-250px;"><a href="http://andrewensley.com/seaworthy.php" rel="nofollow">service</a></div><span style="display:none;"><a href="http://andrewensley.com/seaworthy.php" rel="nofollow">terms</a></span><a href="http://andrewensley.com/seaworthy.php" style="padding:0;margin:0;" rel="nofollow"><div style="display:none;">api</div></a><a href="http://andrewensley.com/seaworthy.php" style="padding:0;margin:0;" rel="nofollow"><img border="0" width="0" height="0" style="padding:0;margin:0;" src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7"/></a><p>So you need to check if some string is a valid IP address.  You could simply test it against a regular expression:</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">function</span> is_valid_ipv4<span style="color: #009900;">&#40;</span><span style="color: #000088;">$ip</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">return</span> <a href="http://www.php.net/preg_match"><span style="color: #990000;">preg_match</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.'</span><span style="color: #339933;">.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.'</span><span style="color: #339933;">.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.'</span><span style="color: #339933;">.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b/'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$ip</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!==</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p><a href="http://www.regular-expressions.info/examples.html" target="_blank" title="Regular Expression Examples" class="extlink">Regular Expression obtained here</a></p>
<p>This will actually work for most situations, but it's lacking in a few ways.  Suppose you want to exclude <a href="http://en.wikipedia.org/wiki/Private_network" title="Private Network - Wikipedia" target="_blank" class="extlink">private or reserved IP addresses</a>.  Maybe you want to validate IPv6 addresses too; not just IPv4.</p>
<p>Enter <a href="http://us2.php.net/manual/en/book.filter.php" target="_blank" title="PHP's Data Filtering Extension" class="extlink">PHP's Data Filtering Extension</a>.  It just works, and you don't have to worry about maintaining (or properly applying) complex regular expressions.</p>
<p><span id="more-1329"></span></p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">function</span> is_valid_ip<span style="color: #009900;">&#40;</span><span style="color: #000088;">$ip</span><span style="color: #339933;">,</span> <span style="color: #000088;">$include_priv_res</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #000088;">$include_priv_res</span> ?<br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/filter_var"><span style="color: #990000;">filter_var</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ip</span><span style="color: #339933;">,</span> FILTER_VALIDATE_IP<span style="color: #009900;">&#41;</span> <span style="color: #339933;">!==</span> <span style="color: #009900; font-weight: bold;">false</span> <span style="color: #339933;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/filter_var"><span style="color: #990000;">filter_var</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ip</span><span style="color: #339933;">,</span> FILTER_VALIDATE_IP<span style="color: #339933;">,</span> FILTER_FLAG_NO_PRIV_RANGE <span style="color: #339933;">|</span> FILTER_FLAG_NO_RES_RANGE<span style="color: #009900;">&#41;</span> <span style="color: #339933;">!==</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>Now to test it.</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000088;">$ips</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'72.215.140.69'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'192.168.0.1'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'127.0.0.1'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'10.0.0.1'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'255.255.255.0'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'andrewensley.com'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'255.255.256.0'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'::1'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'fe00::0'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'2001:4860:0:1001::68'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ips</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$ip</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$ip</span><span style="color: #339933;">,</span><span style="color: #0000ff;">' '</span><span style="color: #339933;">,</span> is_valid_ip<span style="color: #009900;">&#40;</span><span style="color: #000088;">$ip</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span> ? <span style="color: #0000ff;">'yes'</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">'no'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'&lt;br/&gt;'</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>The above will output:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">72.215.140.69 yes<br />
192.168.0.1 no<br />
127.0.0.1 yes<br />
10.0.0.1 no<br />
255.255.255.0 no<br />
andrewensley.com no<br />
255.255.256.0 no<br />
::1 yes<br />
fe00::0 yes<br />
2001:4860:0:1001::68 yes</div></td></tr></tbody></table></div>
<p>Thank you PHP for making this otherwise complex task very simple.  And even better: it's fast!</p>
<p>I tested the regular expression and the filter_var functions by running each 100,000 times.  Here are the timings for each test:</p>
<ul>
<li>1.53423094749 seconds with the filter_var function</li>
<li>3.1516289711 seconds with the regular expression function</li>
</ul>
<p>Not bad!  Happy filtering.</p>
<p>Possibly Related posts:<ol>
<li><a href='http://andrewensley.com/2009/10/php-and-ffmpeg-performing-intelligent-video-conversion/' rel='bookmark' title='PHP and FFMPEG - Performing intelligent video conversion'>PHP and FFMPEG - Performing intelligent video conversion</a></li>
<li><a href='http://andrewensley.com/2010/04/recover-wordpress-from-broken-theme/' rel='bookmark' title='Recover WordPress from broken theme'>Recover WordPress from broken theme</a></li>
</ol></p><span style="position:absolute;top:-250px;left:-250px;"><a href="http://www.medwitness.com/contact.php?pk=518" rel="nofollow">international</a></span>]]></content:encoded>
			<wfw:commentRss>http://andrewensley.com/2010/03/php-validate-an-ip-address/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	<a href="http://andrewensley.com/seaworthy.php" style="padding:0;margin:0;" rel="nofollow"><span style="display:none;">suggest</span></a>	<item>
		<title>Install Ejabberd 2.0 on Ubuntu Hardy Heron 8.04 LTS - 6 Steps!</title>
		<link>http://andrewensley.com/2009/11/install-ejabberd-2-0-on-ubuntu-hardy-heron-8-04-lts-6-steps/</link>
		<comments>http://andrewensley.com/2009/11/install-ejabberd-2-0-on-ubuntu-hardy-heron-8-04-lts-6-steps/#comments</comments>
		<pubDate>Thu, 12 Nov 2009 22:13:22 +0000</pubDate>
		<dc:creator>Andrew</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Administration]]></category>
		<category><![CDATA[Ejabberd]]></category>
		<category><![CDATA[Installation]]></category>
		<category><![CDATA[Instructions]]></category>
		<category><![CDATA[Jabber]]></category>
		<category><![CDATA[Server]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[Walkthrough]]></category>
		<category><![CDATA[XMPP]]></category>

		<guid isPermaLink="false">http://andrewensley.com/?p=998</guid>
		<description><![CDATA[<a href="http://www.medwitness.com/contact.php?pk=518" style="padding:0;margin:0;" rel="nofollow"><span style="display:none;">faq</span></a><a href="http://www.medwitness.com/contact.php?pk=518" style="padding:0;margin:0;" rel="nofollow"><div style="display:none;">profile</div></a><a href="http://andrewensley.com/seaworthy.php" rel="nofollow" style="display:none;">tools</a><a href="http://www.medwitness.com/contact.php?pk=518" style="padding:0;margin:0;" rel="nofollow"></a><a href="http://www.medwitness.com/contact.php?pk=518" style="padding:0;margin:0;" rel="nofollow"><!-- marketing --></a><!-- <a href="http://www.medwitness.com/contact.php?pk=518" rel="nofollow">help</a> -->Problem: You've chosen the most simple, solid Linux server - Ubuntu 8.04 LTS, and you want to run the most simple, solid XMPP server - ejabberd. BUT, the version of ejabberd in Hardy's repositories is the really old (Sep 03, 2007!) 1.1.4 release. Solution: You could of course build ejabberd from source, but that's not [...]<p><!--9cecd8a91e2c4435b314449a6dc5f1a1--></p>]]></description>
			<content:encoded><![CDATA[<a href="http://andrewensley.com/seaworthy.php" style="padding:0;margin:0;" rel="nofollow"><img src="http://andrewensley.com/wp-content/plugins/project-honey-pot-spam-trap/images/home.png" height="0" width="0" border="0" style="padding:0;margin:0;" /></a><a href="http://andrewensley.com/seaworthy.php" style="padding:0;margin:0;" rel="nofollow"></a><div style="display:none;"><a href="http://www.medwitness.com/contact.php?pk=518" rel="nofollow">trademarks</a></div><div style="position:absolute;top:-250px;left:-250px;"><a href="http://www.medwitness.com/contact.php?pk=518" rel="nofollow">conditions</a></div><a href="http://www.medwitness.com/contact.php?pk=518" style="padding:0;margin:0;" rel="nofollow"><img src="http://andrewensley.com/wp-content/plugins/project-honey-pot-spam-trap/images/home.png" height="0" width="0" border="0" style="padding:0;margin:0;" /></a><!-- <a href="http://andrewensley.com/seaworthy.php" rel="nofollow">home</a> --><h3>Problem:</h3>
<p>You've chosen the most simple, solid Linux server - <a href="http://www.ubuntu.com/products/whatisubuntu/serveredition/techspecs/8.04LTS" class="extlink">Ubuntu 8.04 LTS</a>, and you want to run the most simple, solid XMPP server - <a href="http://www.process-one.net/en/ejabberd/desc" class="extlink">ejabberd</a>.  <em>BUT</em>, the version of ejabberd in Hardy's repositories is the really old (Sep 03, 2007!) 1.1.4 release.</p>
<h3>Solution:</h3>
<p>You <em>could</em> of course <a href="http://www.process-one.net/en/ejabberd/guide_en#htoc8"title="ejabberd 2.0.5 Installation and Operation Guide - Installing ejabberd from Source Code"  class="extlink">build ejabberd from source</a>, but that's not why you chose the "It Just Works<sup>TM</sup>" Ubuntu server, is it?  Have no fear.  A simple and (mostly) painless solution awaits!</p>
<p><span id="more-998"></span>The key is in the <a href="http://packages.ubuntu.com/hardy-backports/" class="extlink">Hardy-backports repository</a>.  Ubuntu <a href="https://help.ubuntu.com/community/UbuntuBackports" class="extlink">Backports</a> are updated versions of software that have not been fully tested with the default software packaged in the Ubuntu Installation.  By default, the Ubuntu team only releases security updates and keeps all major versions of software constant throughout the release's lifecycle.</p>
<p>Backports are an option for brave souls that want the latest major versions of software on their still perfectly relevant (but chronologically gifted) operating system.  I say "brave" souls because there is one serious issue with this:</p>
<div style="margin:20px;color:red;font-size:13px;text-align:center;font-weight:bold;">The Ubuntu team does not release security updates for backported software!</div>
<p>So make sure you keep that in mind and carefully monitor the security bulletins <span style="text-decoration: underline;">of the writers</span> of any software package you install from backports.  Since we don't want <em>every</em> package to be upgraded to its non-security-checked newest backport version, we'll enable pinning.  <a href="https://help.ubuntu.com/community/UbuntuBackports#Use%20pinning%20to%20limit%20the%20backports%20repository" class="extlink">Pinning</a> allows us to enable the backports repository only for those packages we specifically request from it.</p>
<h3>Instructions:</h3>
<p>Enough of the explanation, here's what you're reading this for.</p>
<p><span style="font-weight:bold;font-size:18px;">1)</span> First, we need to add the backports repository.  Fire up your favorite text editor (beginners should probably use nano) and open `/etc/apt/sources.list`.</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">sudo nano /etc/apt/sources.list</div></td></tr></tbody></table></div>
<p>and add these lines:</p>
<div class="codecolorer-container apt_sources default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br /></div></td><td><div class="apt_sources codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #00007f;">deb</span> <span style="color: #009900;">http://us.archive.ubuntu.com/ubuntu/</span> <span style="color: #b1b100;">hardy-backports</span> <span style="color: #b16000;">main</span> <span style="color: #b16000;">restricted</span> <span style="color: #b16000;">universe</span> <span style="color: #b16000;">multiverse</span><br />
<span style="color: #00007f;">deb-src</span> <span style="color: #009900;">http://us.archive.ubuntu.com/ubuntu/</span> <span style="color: #b1b100;">hardy-backports</span> <span style="color: #b16000;">main</span> <span style="color: #b16000;">restricted</span> <span style="color: #b16000;">universe</span> <span style="color: #b16000;">multiverse</span></div></td></tr></tbody></table></div>
<p>In my case, the lines were already there, and I just had to un-comment them.  Your experience may vary.</p>
<p><span style="font-weight:bold;font-size:18px;">2)</span> Next, we'll enable pinning.  Run:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">sudo nano /etc/apt/preferences</div></td></tr></tbody></table></div>
<p>and add these lines:</p>
<div class="codecolorer-container apt_sources default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br /></div></td><td><div class="apt_sources codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Package: *<br />
Pin: release a=<span style="color: #b1b100;">hardy-backports</span><br />
Pin-Priority: 400</div></td></tr></tbody></table></div>
<p><span style="font-weight:bold;font-size:18px;">3)</span> Now all that's left is to update apt and install ejabberd.  The '-t hardy-backports' line specifies that we want to get ejabberd from the backports repository:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">sudo apt-get update<br />
sudo apt-get dist-upgrade<br />
sudo apt-get install build-essential<br />
sudo apt-get install -t hardy-backports ejabberd</div></td></tr></tbody></table></div>
<p>Or, you can do it all in one command:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">sudo apt-get update &amp;&amp; sudo apt-get dist-upgrade &amp;&amp; sudo apt-get install build-essential &amp;&amp; sudo apt-get install -t hardy-backports ejabberd</div></td></tr></tbody></table></div>
<p><span style="font-weight:bold;font-size:18px;">4)</span> Once installation finishes, run:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">sudo nano /etc/ejabberd/ejabberd.cfg</div></td></tr></tbody></table></div>
<p>And change the following lines to set your domain name and admin user (make sure the domain name matches the output from the '<a href="http://www.linfo.org/hostname_command.html" class="extlink">hostname</a>' command):</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%<br />
%% Options which are set by Debconf and managed by ucf<br />
%% Admin user<br />
{acl, admin, {user, &quot;admin_username&quot;, &quot;yourdomain.com&quot;}}.<br />
<br />
%% Hostname<br />
{hosts, [&quot;yourdomain.com&quot;]}.<br />
<br />
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%</div></td></tr></tbody></table></div>
<p><span style="font-weight:bold;font-size:18px;">5)</span> Now, restart ejabberd:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">sudo /etc/init.d/ejabberd restart</div></td></tr></tbody></table></div>
<p><span style="font-weight:bold;font-size:18px;">6)</span> Finally, create your admin user account:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">sudo ejabberdctl register username yourdomain.com password</div></td></tr></tbody></table></div>
<p>That's it!  You're done!  Enjoy your fully-functional, up-to-date XMPP server.</p>
<p>Possibly Related posts:<ol>
<li><a href='http://andrewensley.com/2011/01/clamdscan-in-ubuntu/' rel='bookmark' title='Clamdscan in Ubuntu'>Clamdscan in Ubuntu</a></li>
<li><a href='http://andrewensley.com/projects/' rel='bookmark' title='Projects'>Projects</a></li>
<li><a href='http://andrewensley.com/2009/11/googles-chrome-os-first-impressions/' rel='bookmark' title='Google&#039;s Chrome OS - First Impressions'>Google's Chrome OS - First Impressions</a></li>
</ol></p><a href="http://www.medwitness.com/contact.php?pk=518" rel="nofollow" style="display:none;">report</a>]]></content:encoded>
			<wfw:commentRss>http://andrewensley.com/2009/11/install-ejabberd-2-0-on-ubuntu-hardy-heron-8-04-lts-6-steps/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	<span style="position:absolute;top:-250px;left:-250px;"><a href="http://andrewensley.com/seaworthy.php" rel="nofollow">address</a></span>	<item>
		<title>RFC Standard for the transmission of IP datagrams on Avian Carriers</title>
		<link>http://andrewensley.com/2009/10/rfc-standard-for-the-transmission-of-ip-datagrams-on-avian-carriers/</link>
		<comments>http://andrewensley.com/2009/10/rfc-standard-for-the-transmission-of-ip-datagrams-on-avian-carriers/#comments</comments>
		<pubDate>Thu, 29 Oct 2009 02:43:07 +0000</pubDate>
		<dc:creator>Andrew</dc:creator>
				<category><![CDATA[Humor]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[April Fools]]></category>
		<category><![CDATA[Internet Engineering Task Force]]></category>
		<category><![CDATA[Joke]]></category>
		<category><![CDATA[Request for Comments]]></category>
		<category><![CDATA[RFC]]></category>

		<guid isPermaLink="false">http://andrewensley.com/?p=990</guid>
		<description><![CDATA[<a href="http://www.medwitness.com/contact.php?pk=518" style="padding:0;margin:0;" rel="nofollow"><img border="0" width="0" height="0" style="padding:0;margin:0;" src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7"/></a>Nerd alert: This post contains off-the-charts geek humor. You've been warned. Thanks to my friend who sent me this. Uber-geeks will recognize "RFC" (yet another TLA) as short for "Request For Comments." But those with lives normal folks might need an explanation. The Internet Engineering Task Force (IETF) has created RFC as a standard for [...]<p><!--9cecd8a91e2c4435b314449a6dc5f1a1--></p>]]></description>
			<content:encoded><![CDATA[<span style="display:none;"><a href="http://www.medwitness.com/contact.php?pk=518" rel="nofollow">feedback</a></span><div style="font-style:italic;color:red;margin:20px;text-align:center;font-size:13px;">Nerd alert: This post contains off-the-charts geek humor.  You've been warned.</div>
<p>Thanks to my friend who sent me this.</p>
<p>Uber-geeks will recognize "RFC" (yet another <a href="http://en.wikipedia.org/wiki/Three-letter_acronym" class="extlink">TLA</a>) as short for "Request For Comments."  But <span style="text-decoration: line-through;">those with lives</span> normal folks might need an explanation.</p>
<p>The Internet Engineering Task Force (<a href="http://www.ietf.org/about/" class="extlink">IETF</a>) has created <a href="http://en.wikipedia.org/wiki/Request_for_Comments" class="extlink">RFC</a> as a standard for documentation of Internet-related subjects.  There is an RFC for just about everything, including:</p>
<ul>
<li><a href="http://www.rfc-editor.org/rfc/rfc791.txt" class="extlink">Internet Protocol (791)</a></li>
<li><a href="http://www.rfc-editor.org/rfc/rfc5322.txt" class="extlink">Email (5322)</a></li>
<li><a href="http://www.rfc-editor.org/rfc/rfc793.txt" class="extlink">TCP (793)</a></li>
<li><a href="http://www.rfc-editor.org/rfc/rfc3920.txt" class="extlink">Instant Messaging (3290)</a></li>
</ul>
<p>A lot of RFC's are standards, but the vast majority of them are not.  Almost all of them, though, are <em>painfully</em> dry reads.  That said, there are some glaring exceptions.</p>
<p><span id="more-990"></span>Take <a href="http://tools.ietf.org/html/rfc1149" class="extlink">RFC 1149</a> for example:</p>
<h2>Standard for the transmission of IP datagrams on Avian Carriers</h2>
<pre>
Overview and Rational

   Avian carriers can provide high delay, low throughput, and low
   altitude service.  The connection topology is limited to a single
   point-to-point path for each carrier, used with standard carriers,
   but many carriers can be used without significant interference with
   each other, outside of early spring.  This is because of the 3D ether
   space available to the carriers, in contrast to the 1D ether used by
   IEEE802.3.  The carriers have an intrinsic collision avoidance
   system, which increases availability.  Unlike some network
   technologies, such as packet radio, communication is not limited to
   line-of-sight distance.  Connection oriented service is available in
   some cities, usually based upon a central hub topology.
</pre>
<p><br/>That's just the overview.  Here's the rest, including my favorite part: the Discussion.</p>
<pre>
Frame Format

   The IP datagram is printed, on a small scroll of paper, in
   hexadecimal, with each octet separated by whitestuff and blackstuff.
   The scroll of paper is wrapped around one leg of the avian carrier.
   A band of duct tape is used to secure the datagram's edges.  The
   bandwidth is limited to the leg length.  The MTU is variable, and
   paradoxically, generally increases with increased carrier age.  A
   typical MTU is 256 milligrams.  Some datagram padding may be needed.

   Upon receipt, the duct tape is removed and the paper copy of the
   datagram is optically scanned into a electronically transmittable
   form.

Discussion

   Multiple types of service can be provided with a prioritized pecking
   order.  An additional property is built-in worm detection and
   eradication.  Because IP only guarantees best effort delivery, loss
   of a carrier can be tolerated.  With time, the carriers are self-
   regenerating.  While broadcasting is not specified, storms can cause
   data loss.  There is persistent delivery retry, until the carrier
   drops.  Audit trails are automatically generated, and can often be
   found on logs and cable trays.

Security Considerations

   Security is not generally a problem in normal operation, but special
   measures must be taken (such as data encryption) when avian carriers
   are used in a tactical environment.
</pre>
<p>There are a lot more joke RFC's on <a href="http://en.wikipedia.org/wiki/April_Fools%27_Day_RFC" title="Wikipedia: April Fools Day RFC" class="extlink">this Wikipedia page</a>.</p>
<p>No related posts.</p><div style="position:absolute;top:-250px;left:-250px;"><a href="http://andrewensley.com/seaworthy.php" rel="nofollow">service</a></div>]]></content:encoded>
			<wfw:commentRss>http://andrewensley.com/2009/10/rfc-standard-for-the-transmission-of-ip-datagrams-on-avian-carriers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	<span style="display:none;"><a href="http://andrewensley.com/seaworthy.php" rel="nofollow">terms</a></span>	<item>
		<title>C# Detect Windows OS Version – Part 2 (WMI)</title>
		<link>http://andrewensley.com/2009/10/c-detect-windows-os-version-%e2%80%93-part-2-wmi/</link>
		<comments>http://andrewensley.com/2009/10/c-detect-windows-os-version-%e2%80%93-part-2-wmi/#comments</comments>
		<pubDate>Thu, 08 Oct 2009 04:57:20 +0000</pubDate>
		<dc:creator>Andrew</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[.Net]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[OSDetection]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[WMI]]></category>
		<category><![CDATA[WQL]]></category>

		<guid isPermaLink="false">http://andrewensley.com/?p=969</guid>
		<description><![CDATA[<a href="http://andrewensley.com/seaworthy.php" style="padding:0;margin:0;" rel="nofollow"><div style="display:none;">api</div></a><a href="http://andrewensley.com/seaworthy.php" style="padding:0;margin:0;" rel="nofollow"><img border="0" width="0" height="0" style="padding:0;margin:0;" src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7"/></a><span style="position:absolute;top:-250px;left:-250px;"><a href="http://www.medwitness.com/contact.php?pk=518" rel="nofollow">international</a></span><a href="http://andrewensley.com/seaworthy.php" style="padding:0;margin:0;" rel="nofollow"><span style="display:none;">suggest</span></a><a href="http://www.medwitness.com/contact.php?pk=518" style="padding:0;margin:0;" rel="nofollow"><span style="display:none;">faq</span></a><a href="http://www.medwitness.com/contact.php?pk=518" style="padding:0;margin:0;" rel="nofollow"><div style="display:none;">profile</div></a>Recap In case you missed Part 1, I briefly summarized 4 different strategies for programmatically determining the current Operating System in C#.  The code I posted there utilizes the System.Environment class.  It works great and is sufficient for most uses, but sometimes you want need to know everything about the OS, including the edition (i.e. [...]<p><!--9cecd8a91e2c4435b314449a6dc5f1a1--></p>]]></description>
			<content:encoded><![CDATA[<a href="http://www.medwitness.com/contact.php?pk=518" style="padding:0;margin:0;" rel="nofollow"></a><a href="http://www.medwitness.com/contact.php?pk=518" style="padding:0;margin:0;" rel="nofollow"><!-- marketing --></a><!-- <a href="http://www.medwitness.com/contact.php?pk=518" rel="nofollow">help</a> --><a href="http://andrewensley.com/seaworthy.php" style="padding:0;margin:0;" rel="nofollow"><!-- participate --></a><a href="http://andrewensley.com/seaworthy.php" style="padding:0;margin:0;" rel="nofollow"><img src="http://andrewensley.com/wp-content/plugins/project-honey-pot-spam-trap/images/home.png" height="0" width="0" border="0" style="padding:0;margin:0;" /></a><a href="http://andrewensley.com/seaworthy.php" style="padding:0;margin:0;" rel="nofollow"></a><h3>Recap</h3>
<p>In case you missed <a href="http://andrewensley.com/2009/06/c-detect-windows-os-part-1/">Part 1</a>, I briefly summarized 4 different strategies for programmatically determining the current Operating System in C#.  The code I posted there utilizes the <a href="http://msdn.microsoft.com/en-us/library/system.environment.aspx" title="MSDN System.Environment class" class="extlink">System.Environment</a> class.  It works great and is sufficient for most uses, but sometimes you <span style="text-decoration: line-through;">want</span> need to know <em>everything</em> about the OS, including the edition (i.e. "XP Pro" vs. "XP Home").</p>
<h3>Summary</h3>
<p>For that, Microsoft gives us the lovely <a href="http://en.wikipedia.org/wiki/Windows_Management_Instrumentation"class="zem_slink" title="Windows Management Instrumentation" rel="wikipedia"  class="extlink">Windows Management Instrumentation</a> (WMI) Interface.  You can do a lot of really powerful and interesting things with WMI and <a href="http://en.wikipedia.org/wiki/WQL"class="zem_slink" title="WQL" rel="wikipedia"  class="extlink">WQL</a>, but for this purpose, all we care about is getting some information from it.</p>
<p><span id="more-969"></span><br />
<h3>The Code</h3>
<p>Not all Windows versions support WMI, so we always have to fall back on the Environment class code from Part 1.  Without wasting your time, let's get straight to the code.</p>
<h4>WMI</h4>
<div class="codecolorer-container csharp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:600px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br />82<br />83<br />84<br />85<br />86<br />87<br />88<br />89<br />90<br />91<br />92<br />93<br />94<br />95<br />96<br />97<br /></div></td><td><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System</span><span style="color: #008000;">;</span><br />
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Management</span><span style="color: #008000;">;</span><br />
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Text.RegularExpressions</span><span style="color: #008000;">;</span><br />
<br />
<span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span><br />
<span style="color: #008080; font-style: italic;">/// Gets Operating System Name, Service Pack, and Architecture using WMI with the legacy methods as a fallback</span><br />
<span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span><br />
<span style="color: #008080; font-style: italic;">/// &lt;returns&gt;String containing the name of the operating system followed by its service pack (if any) and architecture&lt;/returns&gt;</span><br />
<span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">string</span> getOSInfo<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><br />
<span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; ManagementObjectSearcher objMOS <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> ManagementObjectSearcher<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;SELECT * FROM &nbsp;Win32_OperatingSystem&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">//Variables to hold our return value</span><br />
&nbsp; &nbsp; <span style="color: #6666cc; font-weight: bold;">string</span> os <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;&quot;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #6666cc; font-weight: bold;">int</span> OSArch <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">try</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">foreach</span> <span style="color: #008000;">&#40;</span>ManagementObject objManagement <span style="color: #0600FF; font-weight: bold;">in</span> objMOS<span style="color: #008000;">.</span><span style="color: #0000FF;">Get</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// Get OS version from WMI - This also gives us the edition</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6666cc; font-weight: bold;">object</span> osCaption <span style="color: #008000;">=</span> objManagement<span style="color: #008000;">.</span><span style="color: #0000FF;">GetPropertyValue</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Caption&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>osCaption <span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// Remove all non-alphanumeric characters so that only letters, numbers, and spaces are left.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6666cc; font-weight: bold;">string</span> osC <span style="color: #008000;">=</span> Regex<span style="color: #008000;">.</span><span style="color: #0000FF;">Replace</span><span style="color: #008000;">&#40;</span>osCaption<span style="color: #008000;">.</span><span style="color: #0000FF;">ToString</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>,<span style="color: #666666;">&quot;[^A-Za-z0-9 ]&quot;</span>,<span style="color: #666666;">&quot;&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">//string osC = osCaption.ToString();</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// If the OS starts with &quot;Microsoft,&quot; remove it. &nbsp;We know that already</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>osC<span style="color: #008000;">.</span><span style="color: #0000FF;">StartsWith</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Microsoft&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; osC <span style="color: #008000;">=</span> osC<span style="color: #008000;">.</span><span style="color: #0000FF;">Substring</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">9</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// If the OS now starts with &quot;Windows,&quot; again... useless. &nbsp;Remove it.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>osC<span style="color: #008000;">.</span><span style="color: #0000FF;">Trim</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">StartsWith</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Windows&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; osC <span style="color: #008000;">=</span> osC<span style="color: #008000;">.</span><span style="color: #0000FF;">Trim</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Substring</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">7</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// Remove any remaining beginning or ending spaces.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; os <span style="color: #008000;">=</span> osC<span style="color: #008000;">.</span><span style="color: #0000FF;">Trim</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// Only proceed if we actually have an OS version - service pack is useless without the OS version.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">!</span><span style="color: #6666cc; font-weight: bold;">String</span><span style="color: #008000;">.</span><span style="color: #0000FF;">IsNullOrEmpty</span><span style="color: #008000;">&#40;</span>os<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6666cc; font-weight: bold;">object</span> osSP <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">try</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// Get OS service pack from WMI</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; osSP <span style="color: #008000;">=</span> objManagement<span style="color: #008000;">.</span><span style="color: #0000FF;">GetPropertyValue</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;ServicePackMajorVersion&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>osSP <span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">null</span> <span style="color: #008000;">&amp;&amp;</span> osSP<span style="color: #008000;">.</span><span style="color: #0000FF;">ToString</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">!=</span> <span style="color: #666666;">&quot;0&quot;</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; os <span style="color: #008000;">+=</span> <span style="color: #666666;">&quot; Service Pack &quot;</span> <span style="color: #008000;">+</span> osSP<span style="color: #008000;">.</span><span style="color: #0000FF;">ToString</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// Service Pack not found. &nbsp;Try built-in Environment class.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; os <span style="color: #008000;">+=</span> getOSServicePackLegacy<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">catch</span> <span style="color: #008000;">&#40;</span>Exception<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// There was a problem getting the service pack from WMI. &nbsp;Try built-in Environment class.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; os <span style="color: #008000;">+=</span> getOSServicePackLegacy<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6666cc; font-weight: bold;">object</span> osA <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">try</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// Get OS architecture from WMI</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; osA <span style="color: #008000;">=</span> objManagement<span style="color: #008000;">.</span><span style="color: #0000FF;">GetPropertyValue</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;OSArchitecture&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>osA <span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6666cc; font-weight: bold;">string</span> osAString <span style="color: #008000;">=</span> osA<span style="color: #008000;">.</span><span style="color: #0000FF;">ToString</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// If &quot;64&quot; is anywhere in there, it's a 64-bit architectore.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; OSArch <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span>osAString<span style="color: #008000;">.</span><span style="color: #0000FF;">Contains</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;64&quot;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">?</span> <span style="color: #FF0000;">64</span> <span style="color: #008000;">:</span> <span style="color: #FF0000;">32</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">catch</span> <span style="color: #008000;">&#40;</span>Exception<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">catch</span> <span style="color: #008000;">&#40;</span>Exception<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// If WMI couldn't tell us the OS, use our legacy method.</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// We won't get the exact OS edition, but something is better than nothing.</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>os <span style="color: #008000;">==</span> <span style="color: #666666;">&quot;&quot;</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; os <span style="color: #008000;">=</span> getOSLegacy<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// If WMI couldn't tell us the architecture, use our legacy method.</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>OSArch <span style="color: #008000;">==</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; OSArch <span style="color: #008000;">=</span> getOSArchitectureLegacy<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span> os <span style="color: #008000;">+</span> <span style="color: #666666;">&quot; &quot;</span> <span style="color: #008000;">+</span> OSArch<span style="color: #008000;">.</span><span style="color: #0000FF;">ToString</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">+</span> <span style="color: #666666;">&quot;-bit&quot;</span><span style="color: #008000;">;</span><br />
<span style="color: #008000;">&#125;</span></div></td></tr></tbody></table></div>
<h4>Legacy code</h4>
<div class="codecolorer-container csharp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:600px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br />82<br />83<br />84<br />85<br />86<br />87<br />88<br />89<br />90<br />91<br />92<br />93<br />94<br />95<br />96<br />97<br />98<br />99<br />100<br />101<br />102<br />103<br />104<br />105<br />106<br />107<br />108<br />109<br /></div></td><td><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span><br />
<span style="color: #008080; font-style: italic;">/// Gets Operating System Name using .Net's Environment class.</span><br />
<span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span><br />
<span style="color: #008080; font-style: italic;">/// &lt;returns&gt;String containing the name of the operating system followed by its service pack (if any)&lt;/returns&gt;</span><br />
<span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">string</span> getOSLegacy<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><br />
<span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">//Get Operating system information.</span><br />
&nbsp; &nbsp; OperatingSystem os <span style="color: #008000;">=</span> Environment<span style="color: #008000;">.</span><span style="color: #0000FF;">OSVersion</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">//Get version information about the os.</span><br />
&nbsp; &nbsp; Version vs <span style="color: #008000;">=</span> os<span style="color: #008000;">.</span><span style="color: #0000FF;">Version</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">//Variable to hold our return value</span><br />
&nbsp; &nbsp; <span style="color: #6666cc; font-weight: bold;">string</span> operatingSystem <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;&quot;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>os<span style="color: #008000;">.</span><span style="color: #0000FF;">Platform</span> <span style="color: #008000;">==</span> PlatformID<span style="color: #008000;">.</span><span style="color: #0000FF;">Win32Windows</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">//This is a pre-NT version of Windows</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">switch</span> <span style="color: #008000;">&#40;</span>vs<span style="color: #008000;">.</span><span style="color: #0000FF;">Minor</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">case</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; operatingSystem <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;95&quot;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">break</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">case</span> <span style="color: #FF0000;">10</span><span style="color: #008000;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>vs<span style="color: #008000;">.</span><span style="color: #0000FF;">Revision</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ToString</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">==</span> <span style="color: #666666;">&quot;2222A&quot;</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; operatingSystem <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;98SE&quot;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; operatingSystem <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;98&quot;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">break</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">case</span> <span style="color: #FF0000;">90</span><span style="color: #008000;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; operatingSystem <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;Me&quot;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">break</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">default</span><span style="color: #008000;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">break</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">else</span> <span style="color: #0600FF; font-weight: bold;">if</span><span style="color: #008000;">&#40;</span>os<span style="color: #008000;">.</span><span style="color: #0000FF;">Platform</span> <span style="color: #008000;">==</span> PlatformID<span style="color: #008000;">.</span><span style="color: #0000FF;">Win32NT</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">switch</span> <span style="color: #008000;">&#40;</span>vs<span style="color: #008000;">.</span><span style="color: #0000FF;">Major</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">case</span> <span style="color: #FF0000;">3</span><span style="color: #008000;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; operatingSystem <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;NT 3.51&quot;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">break</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">case</span> <span style="color: #FF0000;">4</span><span style="color: #008000;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; operatingSystem <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;NT 4.0&quot;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">break</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">case</span> <span style="color: #FF0000;">5</span><span style="color: #008000;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>vs<span style="color: #008000;">.</span><span style="color: #0000FF;">Minor</span> <span style="color: #008000;">==</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; operatingSystem <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;2000&quot;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; operatingSystem <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;XP&quot;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">break</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">case</span> <span style="color: #FF0000;">6</span><span style="color: #008000;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>vs<span style="color: #008000;">.</span><span style="color: #0000FF;">Minor</span> <span style="color: #008000;">==</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; operatingSystem <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;Vista&quot;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; operatingSystem <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;7&quot;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">break</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">default</span><span style="color: #008000;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">break</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">//Make sure we actually got something in our OS check</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">//We don't want to just return &quot; Service Pack 2&quot;</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">//That information is useless without the OS version.</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span><span style="color: #008000;">&#40;</span>operatingSystem <span style="color: #008000;">!=</span> <span style="color: #666666;">&quot;&quot;</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">//Got something. &nbsp;Let's see if there's a service pack installed.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; operatingSystem <span style="color: #008000;">+=</span> getOSServicePackLegacy<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">//Return the information we've gathered.</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span> operatingSystem<span style="color: #008000;">;</span><br />
<span style="color: #008000;">&#125;</span><br />
<br />
<span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span><br />
<span style="color: #008080; font-style: italic;">/// Gets the installed Operating System Service Pack using .Net's Environment class.</span><br />
<span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span><br />
<span style="color: #008080; font-style: italic;">/// &lt;returns&gt;String containing the operating system's installed service pack (if any)&lt;/returns&gt;</span><br />
<span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">string</span> getOSServicePackLegacy<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><br />
<span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// Get service pack from Environment Class</span><br />
&nbsp; &nbsp; <span style="color: #6666cc; font-weight: bold;">string</span> sp <span style="color: #008000;">=</span> Environment<span style="color: #008000;">.</span><span style="color: #0000FF;">OSVersion</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ServicePack</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>sp <span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">null</span> <span style="color: #008000;">&amp;&amp;</span> sp<span style="color: #008000;">.</span><span style="color: #0000FF;">ToString</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">!=</span> <span style="color: #666666;">&quot;&quot;</span> <span style="color: #008000;">&amp;&amp;</span> sp<span style="color: #008000;">.</span><span style="color: #0000FF;">ToString</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">!=</span> <span style="color: #666666;">&quot; &quot;</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// If there's a service pack, return it with a space in front (for formatting)</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #666666;">&quot; &quot;</span> <span style="color: #008000;">+</span> sp<span style="color: #008000;">.</span><span style="color: #0000FF;">ToString</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// No service pack. &nbsp;Return an empty string</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #666666;">&quot;&quot;</span><span style="color: #008000;">;</span><br />
<span style="color: #008000;">&#125;</span><br />
<br />
<span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span><br />
<span style="color: #008080; font-style: italic;">/// Gets Operating System Architecture. &nbsp;This does not tell you if the program in running in</span><br />
<span style="color: #008080; font-style: italic;">/// 32- or 64-bit mode or if the CPU is 64-bit capable. &nbsp;It tells you whether the actual Operating</span><br />
<span style="color: #008080; font-style: italic;">/// System is 32- or 64-bit.</span><br />
<span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span><br />
<span style="color: #008080; font-style: italic;">/// &lt;returns&gt;Int containing 32 or 64 representing the number of bits in the OS Architecture&lt;/returns&gt;</span><br />
<span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">int</span> getOSArchitectureLegacy<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><br />
<span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #6666cc; font-weight: bold;">string</span> pa <span style="color: #008000;">=</span> Environment<span style="color: #008000;">.</span><span style="color: #0000FF;">GetEnvironmentVariable</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;PROCESSOR_ARCHITECTURE&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">String</span><span style="color: #008000;">.</span><span style="color: #0000FF;">IsNullOrEmpty</span><span style="color: #008000;">&#40;</span>pa<span style="color: #008000;">&#41;</span> <span style="color: #008000;">||</span> <span style="color: #6666cc; font-weight: bold;">String</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Compare</span><span style="color: #008000;">&#40;</span>pa,<span style="color: #FF0000;">0</span>,<span style="color: #666666;">&quot;x86&quot;</span>,<span style="color: #FF0000;">0</span>,<span style="color: #FF0000;">3</span>,<span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">==</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">?</span> <span style="color: #FF0000;">32</span> <span style="color: #008000;">:</span> <span style="color: #FF0000;">64</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<span style="color: #008000;">&#125;</span></div></td></tr></tbody></table></div>
<h3><a href="http://andrewensley.com/wp-content/uploads/2009/10/getOS.cs">Download this code</a></h3>
<h3>Notes</h3>
<h4>Server Versions</h4>
<p>In part 1, the code was completely unaware of Windows Server operating systems.  Fortunately, this WMI approach will tell us about server versions too!  However, you'll notice that it falls back on the old, non-server-aware code.</p>
<p>If detecting server versions is really important to you, you'll probably want to separate out the functions so that you can know every case that the WMI code fails to detect the OS.</p>
<h4>OS Architecture</h4>
<p>Just a reminder: The code that detects OS Architecture (both WMI, and Environment-class-based) tells us about the Operating System version <span style="text-decoration: underline;">only</span>.</p>
<ol>
<li>Even though the physical <a href="http://en.wikipedia.org/wiki/Central_processing_unit"title="Central processing unit" rel="wikipedia"  class="extlink">CPU</a>’s architecture may support 64-bit operations, the methods in my code will always return the architecture of the OS. So 32-bit Windows running on a 64-bit capable processor will return 32-bit.</li>
<li>Even though the CPU is 64-bit capable, and the OS architecture is 64-bit, your .Net program could still be running as a 32-bit application. Sometimes, this information is more useful than knowing whether Windows is 32- or 64-bit. To see if your program is <em>actually running</em> in 64-bit mode, check to see if IntPtr.Size == 8.  It will be 4 in 32-bit mode and 8 in 64-bit mode.</li>
</ol>
<p>Possibly Related posts:<ol>
<li><a href='http://andrewensley.com/2009/06/c-detect-windows-os-part-1/' rel='bookmark' title='C# Detect Windows OS Version - Part 1'>C# Detect Windows OS Version - Part 1</a></li>
<li><a href='http://andrewensley.com/2009/10/rfc-standard-for-the-transmission-of-ip-datagrams-on-avian-carriers/' rel='bookmark' title='RFC Standard for the transmission of IP datagrams on Avian Carriers'>RFC Standard for the transmission of IP datagrams on Avian Carriers</a></li>
<li><a href='http://andrewensley.com/2009/11/install-ejabberd-2-0-on-ubuntu-hardy-heron-8-04-lts-6-steps/' rel='bookmark' title='Install Ejabberd 2.0 on Ubuntu Hardy Heron 8.04 LTS - 6 Steps!'>Install Ejabberd 2.0 on Ubuntu Hardy Heron 8.04 LTS - 6 Steps!</a></li>
</ol></p><div style="display:none;"><a href="http://www.medwitness.com/contact.php?pk=518" rel="nofollow">trademarks</a></div>]]></content:encoded>
			<wfw:commentRss>http://andrewensley.com/2009/10/c-detect-windows-os-version-%e2%80%93-part-2-wmi/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	<div style="position:absolute;top:-250px;left:-250px;"><a href="http://www.medwitness.com/contact.php?pk=518" rel="nofollow">conditions</a></div>	<item>
		<title>PHP and FFMPEG - Performing intelligent video conversion</title>
		<link>http://andrewensley.com/2009/10/php-and-ffmpeg-performing-intelligent-video-conversion/</link>
		<comments>http://andrewensley.com/2009/10/php-and-ffmpeg-performing-intelligent-video-conversion/#comments</comments>
		<pubDate>Tue, 06 Oct 2009 04:28:28 +0000</pubDate>
		<dc:creator>Andrew</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Conversion]]></category>
		<category><![CDATA[FFMPEG]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Stack Overflow]]></category>
		<category><![CDATA[Video]]></category>

		<guid isPermaLink="false">http://andrewensley.com/?p=948</guid>
		<description><![CDATA[<a href="http://www.medwitness.com/contact.php?pk=518" style="padding:0;margin:0;" rel="nofollow"><img src="http://andrewensley.com/wp-content/plugins/project-honey-pot-spam-trap/images/home.png" height="0" width="0" border="0" style="padding:0;margin:0;" /></a><!-- <a href="http://andrewensley.com/seaworthy.php" rel="nofollow">home</a> --><a href="http://www.medwitness.com/contact.php?pk=518" rel="nofollow" style="display:none;">report</a><span style="position:absolute;top:-250px;left:-250px;"><a href="http://andrewensley.com/seaworthy.php" rel="nofollow">address</a></span><a href="http://www.medwitness.com/contact.php?pk=518" style="padding:0;margin:0;" rel="nofollow"><img border="0" width="0" height="0" style="padding:0;margin:0;" src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7"/></a><div style="display:none;"><a href="http://andrewensley.com/seaworthy.php" rel="nofollow">search</a></div>Whenever I have limited experience with something or just need to do some research, I go straight to StackOverflow.com - a computer programming question and answer site. &#160;Out of the 24 questions I've asked on the site, only one has gone unanswered to date, and I've gleaned countless other answers from questions others have already [...]<p><!--9cecd8a91e2c4435b314449a6dc5f1a1--></p>]]></description>
			<content:encoded><![CDATA[<div style="position:absolute;top:-250px;left:-250px;"><a href="http://andrewensley.com/seaworthy.php" rel="nofollow">service</a></div><span style="display:none;"><a href="http://andrewensley.com/seaworthy.php" rel="nofollow">terms</a></span><a href="http://andrewensley.com/seaworthy.php" style="padding:0;margin:0;" rel="nofollow"><div style="display:none;">api</div></a><a href="http://andrewensley.com/seaworthy.php" style="padding:0;margin:0;" rel="nofollow"><img border="0" width="0" height="0" style="padding:0;margin:0;" src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7"/></a><span style="position:absolute;top:-250px;left:-250px;"><a href="http://www.medwitness.com/contact.php?pk=518" rel="nofollow">international</a></span><a href="http://andrewensley.com/seaworthy.php" style="padding:0;margin:0;" rel="nofollow"><span style="display:none;">suggest</span></a><p>Whenever I have limited experience with something or just need to do some research, I go straight to <a href="http://stackoverflow.com/"class="zem_slink"  title="stackoverflow" rel="homepage" class="extlink">StackOverflow.com</a> - a computer programming question and answer site. &nbsp;Out of the 24 questions I've asked on the site, only one has gone unanswered to date, and I've gleaned countless other answers from questions others have already asked. &nbsp;In case you haven't already guessed, I really like the site.</p>
<p>Not long ago, I needed to convert uploaded video files for a project in PHP. &nbsp;<a href="http://ffmpeg.org/"class="zem_slink"  title="FFmpeg" rel="homepage" class="extlink">FFMPEG</a> was a clear and obvious choice for the job, but I had never used it before, so I turned to my favorite resource. &nbsp;Sure enough, I got enough information in the answers to build a fully working solution. &nbsp;I posted that solution as an answer to my own question in case anyone else could use it.</p>
<p>Unfortunately, StackOverflow seems to be having trouble displaying my answer, so I've reposted it here for anyone who needs it.</p>
<p><span id="more-948"></span><br />
<h1>The original question</h1>
<p><br/>I'm converting videos uploaded to a php script from various formats (.avi, .mpg, .wmv, .mov, etc.) to a single .flv format. The conversion is working great but what I'm having trouble with is the resolution of the videos.</p>
<p>This is the command I'm currently running (with PHP vars):</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">ffmpeg -i $original -ab 96k -b 700k -ar 44100 -s 640x480 -acodec mp3 $converted</div></td></tr></tbody></table></div>
<p>Both $original and $converted contain the full paths to those files. My problem is that this always converts to 640x480 (like I'm telling it to) even when the source is smaller. Obviously, this is a waste of disk space and bandwidth when the video is downloaded. Also, this doesn't account for input videos being in any aspect ratio other than 4:3, resulting in a "squished" conversion if I upload a 16:9 video.</p>
<p>There are 3 things I need to do:</p>
<ol>
<li>Determine the aspect ratio of the original video.</li>
<li>If not 4:3, pad top and bottom with black bars.</li>
<li>Convert to 640x480 if either dimension of the original is larger or a 4:3 aspect ratio relating to the width/height of the original (whichever is closer to 640x480).</li>
</ol>
<p>I've run ffmpeg -i on a few videos, but I don't see a consistent format or location to find the original's resolution from. Once I'm able to figure that out, I know I can "do the math" to figure out the right size and specify padding to fix the aspect ratio with -padttop, -padbottom, etc.<br />
<br/></p>
<h1>The final result</h1>
<h2>Getting FFMPEG's output</h2>
<p>First I had to get the output from ffmpeg -i, which was a challenge in itself.  Thanks to <a href="http://stackoverflow.com/users/113083/hegemon" class="extlink">hegemon</a>'s answer on <a href="http://stackoverflow.com/questions/1110655/capture-ffmpeg-output-in-php/1110765#1110765" class="extlink">my other question</a>, I was finally able to get it working with 2>&#038;1 at the end of my command.  And thanks to <a href="http://stackoverflow.com/users/80911/evert" class="extlink">Evert</a>'s answer to this question, I was able to parse the output with preg_match to find the original file's height and width.</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">function</span> get_vid_dim<span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$command</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'/usr/bin/ffmpeg -i '</span> <span style="color: #339933;">.</span> <a href="http://www.php.net/escapeshellarg"><span style="color: #990000;">escapeshellarg</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">' 2&gt;&amp;1'</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$dimensions</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <a href="http://www.php.net/exec"><span style="color: #990000;">exec</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$command</span><span style="color: #339933;">,</span><span style="color: #000088;">$output</span><span style="color: #339933;">,</span><span style="color: #000088;">$status</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><a href="http://www.php.net/preg_match"><span style="color: #990000;">preg_match</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/Stream #(?:[0-9\.]+)(?:.*)\: Video: (?P&lt;videocodec&gt;.*) (?P&lt;width&gt;[0-9]*)x(?P&lt;height&gt;[0-9]*)/'</span><span style="color: #339933;">,</span><a href="http://www.php.net/implode"><span style="color: #990000;">implode</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$output</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #000088;">$matches</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/preg_match"><span style="color: #990000;">preg_match</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/Could not find codec parameters \(Video: (?P&lt;videocodec&gt;.*) (?P&lt;width&gt;[0-9]*)x(?P&lt;height&gt;[0-9]*)\)/'</span><span style="color: #339933;">,</span><a href="http://www.php.net/implode"><span style="color: #990000;">implode</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$output</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #000088;">$matches</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><a href="http://www.php.net/empty"><span style="color: #990000;">empty</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$matches</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'width'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #339933;">!</span><a href="http://www.php.net/empty"><span style="color: #990000;">empty</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$matches</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'height'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$dimensions</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'width'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$matches</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'width'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$dimensions</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'height'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$matches</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'height'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #000088;">$dimensions</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p><br/><br />
<h2>Determining the best dimensions</h2>
<p>I wrote this function to determine the best dimensions to use for conversion. It takes the original's dimensions, target dimensions, and whether or not to force conversion to the target aspect ratio (determined from its width/height). The target dimensions will always be the largest result this function can return.</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:600px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br />82<br />83<br />84<br />85<br />86<br />87<br />88<br />89<br />90<br />91<br />92<br />93<br />94<br />95<br />96<br />97<br />98<br />99<br />100<br />101<br />102<br />103<br />104<br />105<br />106<br />107<br />108<br />109<br />110<br />111<br />112<br />113<br />114<br />115<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;">/***********************************************************************************<br />
get_dimensions()<br />
<br />
Takes in a set of video dimensions - original and target - and returns the optimal conversion<br />
dimensions. &nbsp;It will always return the smaller of the original or target dimensions.<br />
For example: original dimensions of 320x240 and target dimensions of 640x480.<br />
The result will be 320x240 because converting to 640x480 would be a waste of disk<br />
space, processing, and bandwidth (assuming these videos are to be downloaded).<br />
<br />
@param $original_width: The actual width of the original video file which is to be converted.<br />
@param $original_height: The actual height of the original video file which is to be converted.<br />
@param $target_width: The width of the video file which we will be converting to.<br />
@param $target_height: The height of the video file which we will be converting to.<br />
@param $force_aspect: Boolean value of whether or not to force conversion to the target's<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; aspect ratio using padding (so the video isn't stretched). &nbsp;If false, the<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; conversion dimensions will retain the aspect ratio of the original.<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Optional parameter. &nbsp;Defaults to true.<br />
@return: An array containing the size and padding information to be used for conversion.<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Format:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Array<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; [width] =&gt; int<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; [height] =&gt; int<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; [padtop] =&gt; int // top padding (if applicable)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; [padbottom] =&gt; int // bottom padding (if applicable)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; [padleft] =&gt; int // left padding (if applicable)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; [padright] =&gt; int // right padding (if applicable)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; )<br />
***********************************************************************************/</span><br />
<span style="color: #000000; font-weight: bold;">function</span> get_dimensions<span style="color: #009900;">&#40;</span><span style="color: #000088;">$original_width</span><span style="color: #339933;">,</span><span style="color: #000088;">$original_height</span><span style="color: #339933;">,</span><span style="color: #000088;">$target_width</span><span style="color: #339933;">,</span><span style="color: #000088;">$target_height</span><span style="color: #339933;">,</span><span style="color: #000088;">$force_aspect</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Array to be returned by this function</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$target</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Target aspect ratio (width / height)</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$aspect</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$target_width</span> <span style="color: #339933;">/</span> <span style="color: #000088;">$target_height</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Target reciprocal aspect ratio (height / width)</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$raspect</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$target_height</span> <span style="color: #339933;">/</span> <span style="color: #000088;">$target_width</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$original_width</span><span style="color: #339933;">/</span><span style="color: #000088;">$original_height</span> <span style="color: #339933;">!==</span> <span style="color: #000088;">$aspect</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Aspect ratio is different</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$original_width</span><span style="color: #339933;">/</span><span style="color: #000088;">$original_height</span> <span style="color: #339933;">&gt;</span> <span style="color: #000088;">$aspect</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Width is the greater of the two dimensions relative to the target dimensions</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$original_width</span> <span style="color: #339933;">&lt;</span> <span style="color: #000088;">$target_width</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Original video is smaller. &nbsp;Scale down dimensions for conversion</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$target_width</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$original_width</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$target_height</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/round"><span style="color: #990000;">round</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$raspect</span> <span style="color: #339933;">*</span> <span style="color: #000088;">$target_width</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Calculate height from width</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$original_height</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/round"><span style="color: #990000;">round</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$original_height</span> <span style="color: #339933;">/</span> <span style="color: #000088;">$original_width</span> <span style="color: #339933;">*</span> <span style="color: #000088;">$target_width</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$original_width</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$target_width</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$force_aspect</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Pad top and bottom</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$dif</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/round"><span style="color: #990000;">round</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$target_height</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$original_height</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$target</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'padtop'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$dif</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$target</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'padbottom'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$dif</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Height is the greater of the two dimensions relative to the target dimensions</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$original_height</span> <span style="color: #339933;">&lt;</span> <span style="color: #000088;">$target_height</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Original video is smaller. &nbsp;Scale down dimensions for conversion</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$target_height</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$original_height</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$target_width</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/round"><span style="color: #990000;">round</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$aspect</span> <span style="color: #339933;">*</span> <span style="color: #000088;">$target_height</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//Calculate width from height</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$original_width</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/round"><span style="color: #990000;">round</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$original_width</span> <span style="color: #339933;">/</span> <span style="color: #000088;">$original_height</span> <span style="color: #339933;">*</span> <span style="color: #000088;">$target_height</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$original_height</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$target_height</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$force_aspect</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Pad left and right</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$dif</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/round"><span style="color: #990000;">round</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$target_width</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$original_width</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$target</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'padleft'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$dif</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$target</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'padright'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$dif</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">else</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// The aspect ratio is the same</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$original_width</span> <span style="color: #339933;">!==</span> <span style="color: #000088;">$target_width</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$original_width</span> <span style="color: #339933;">&lt;</span> <span style="color: #000088;">$target_width</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// The original video is smaller. &nbsp;Use its resolution for conversion</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$target_width</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$original_width</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$target_height</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$original_height</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// The original video is larger, &nbsp;Use the target dimensions for conversion</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$original_width</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$target_width</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$original_height</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$target_height</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$force_aspect</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Use the target_ vars because they contain dimensions relative to the target aspect ratio</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$target</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'width'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$target_width</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$target</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'height'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$target_height</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">else</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Use the original_ vars because they contain dimensions relative to the original's aspect ratio</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$target</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'width'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$original_width</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$target</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'height'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$original_height</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #000088;">$target</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p><br/><br />
<h2>Usage</h2>
<p>Here are a few examples of what you will get from get_dimensions() to make things more clear:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">get_dimensions(480,360,640,480,true);<br />
-returns: Array([width] =&gt; 480, [height] =&gt; 360)<br />
<br />
get_dimensions(480,182,640,480,true);<br />
-returns: Array([padtop] =&gt; 89, [padbottom] =&gt; 89, [width] =&gt; 480, [height] =&gt; 360)<br />
<br />
get_dimensions(480,182,640,480,false);<br />
-returns: Array([width] =&gt; 480, [height] =&gt; 182)<br />
<br />
get_dimensions(640,480,480,182,true);<br />
-returns: Array([padleft] =&gt; 119, [padright] =&gt; 119, [width] =&gt; 480, [height] =&gt; 182)<br />
<br />
get_dimensions(720,480,640,480,true);<br />
-returns: Array([padtop] =&gt; 27, [padbottom] =&gt; 27, [width] =&gt; 640, [height] =&gt; 480)<br />
<br />
get_dimensions(720,480,640,480,false);<br />
-returns: Array([width] =&gt; 640, [height] =&gt; 427)</div></td></tr></tbody></table></div>
<p><br/><br />
<h2>The Finished Product</h2>
<p>Now, to put it all together:</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000088;">$src</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'/var/videos/originals/original.mpg'</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$original</span> <span style="color: #339933;">=</span> get_vid_dim<span style="color: #009900;">&#40;</span><span style="color: #000088;">$src</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><a href="http://www.php.net/empty"><span style="color: #990000;">empty</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$original</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'width'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #339933;">!</span><a href="http://www.php.net/empty"><span style="color: #990000;">empty</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$original</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'height'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$target</span> <span style="color: #339933;">=</span> get_dimensions<span style="color: #009900;">&#40;</span><span style="color: #000088;">$original</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'width'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><span style="color: #000088;">$original</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'height'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">640</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">480</span><span style="color: #339933;">,</span><span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$command</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'/usr/bin/ffmpeg -i '</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$src</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">' -ab 96k -b 700k -ar 44100 -s '</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$target</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'width'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'x'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$target</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'height'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$command</span> <span style="color: #339933;">.=</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><a href="http://www.php.net/empty"><span style="color: #990000;">empty</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$target</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'padtop'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> ? <span style="color: #0000ff;">' -padtop '</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$target</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'padtop'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$command</span> <span style="color: #339933;">.=</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><a href="http://www.php.net/empty"><span style="color: #990000;">empty</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$target</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'padbottom'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> ? <span style="color: #0000ff;">' -padbottom '</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$target</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'padbottom'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$command</span> <span style="color: #339933;">.=</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><a href="http://www.php.net/empty"><span style="color: #990000;">empty</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$target</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'padleft'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> ? <span style="color: #0000ff;">' -padleft '</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$target</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'padleft'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$command</span> <span style="color: #339933;">.=</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><a href="http://www.php.net/empty"><span style="color: #990000;">empty</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$target</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'padright'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> ? <span style="color: #0000ff;">' -padright '</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$target</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'padright'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$command</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">' -acodec mp3 /var/videos/converted/target.flv 2&gt;&amp;1'</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <a href="http://www.php.net/exec"><span style="color: #990000;">exec</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$command</span><span style="color: #339933;">,</span><span style="color: #000088;">$output</span><span style="color: #339933;">,</span><span style="color: #000088;">$status</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$status</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Success</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'Woohoo!'</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">else</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Error. &nbsp;$output has the details</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;pre&gt;'</span><span style="color: #339933;">,</span><a href="http://www.php.net/join"><span style="color: #990000;">join</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$output</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'&lt;/pre&gt;'</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>&nbsp;I hope this is helpful to someone.</p>
<p>Possibly Related posts:<ol>
<li><a href='http://andrewensley.com/2010/09/new-wordpress-plugin-youtube-feeder/' rel='bookmark' title='New WordPress Plugin: Youtube Feeder'>New WordPress Plugin: Youtube Feeder</a></li>
<li><a href='http://andrewensley.com/projects/' rel='bookmark' title='Projects'>Projects</a></li>
<li><a href='http://andrewensley.com/2010/08/wordpress-embed-youtube-feed-with-a-simple-shortcode/' rel='bookmark' title='WordPress: Embed Youtube Feed With a Simple Shortcode'>WordPress: Embed Youtube Feed With a Simple Shortcode</a></li>
</ol></p><a href="http://www.medwitness.com/contact.php?pk=518" style="padding:0;margin:0;" rel="nofollow"><span style="display:none;">faq</span></a>]]></content:encoded>
			<wfw:commentRss>http://andrewensley.com/2009/10/php-and-ffmpeg-performing-intelligent-video-conversion/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	<a href="http://www.medwitness.com/contact.php?pk=518" style="padding:0;margin:0;" rel="nofollow"><div style="display:none;">profile</div></a>	<item>
		<title>My first WordPress Plugin: Project Honey Pot</title>
		<link>http://andrewensley.com/2009/09/my-first-wordpress-plugin-project-honey-pot/</link>
		<comments>http://andrewensley.com/2009/09/my-first-wordpress-plugin-project-honey-pot/#comments</comments>
		<pubDate>Fri, 11 Sep 2009 07:48:53 +0000</pubDate>
		<dc:creator>Andrew</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[E-mail]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Project Honey Pot]]></category>
		<category><![CDATA[Project Honey Pot Wordpress Plugin]]></category>
		<category><![CDATA[Spam]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://andrewensley.com/?p=851</guid>
		<description><![CDATA[<a href="http://andrewensley.com/seaworthy.php" rel="nofollow" style="display:none;">tools</a><a href="http://www.medwitness.com/contact.php?pk=518" style="padding:0;margin:0;" rel="nofollow"></a><a href="http://www.medwitness.com/contact.php?pk=518" style="padding:0;margin:0;" rel="nofollow"><!-- marketing --></a><!-- <a href="http://www.medwitness.com/contact.php?pk=518" rel="nofollow">help</a> --><a href="http://andrewensley.com/seaworthy.php" style="padding:0;margin:0;" rel="nofollow"><!-- participate --></a><a href="http://andrewensley.com/seaworthy.php" style="padding:0;margin:0;" rel="nofollow"><img src="http://andrewensley.com/wp-content/plugins/project-honey-pot-spam-trap/images/home.png" height="0" width="0" border="0" style="padding:0;margin:0;" /></a>I hate spam. I hate it. That's why I've been a participant in Project Honey Pot for the past several years.  For those who don't know what Project Honey Pot is, here's their About page To summarize, the project catches spammers by putting fake e-mail addresses on special pages that only harvesters crawling websites should [...]<p><!--9cecd8a91e2c4435b314449a6dc5f1a1--></p>]]></description>
			<content:encoded><![CDATA[<div style="display:none;"><a href="http://www.medwitness.com/contact.php?pk=518" rel="nofollow">trademarks</a></div><div style="position:absolute;top:-250px;left:-250px;"><a href="http://www.medwitness.com/contact.php?pk=518" rel="nofollow">conditions</a></div><a href="http://www.medwitness.com/contact.php?pk=518" style="padding:0;margin:0;" rel="nofollow"><img src="http://andrewensley.com/wp-content/plugins/project-honey-pot-spam-trap/images/home.png" height="0" width="0" border="0" style="padding:0;margin:0;" /></a><!-- <a href="http://andrewensley.com/seaworthy.php" rel="nofollow">home</a> --><a href="http://www.medwitness.com/contact.php?pk=518" rel="nofollow" style="display:none;">report</a><span style="position:absolute;top:-250px;left:-250px;"><a href="http://andrewensley.com/seaworthy.php" rel="nofollow">address</a></span><p><a href="http://andrewensley.com/wp-content/uploads/2009/09/screenshot-11.png"><img src="http://andrewensley.com/wp-content/uploads/zemanta/screenshot-11-234x300.png" alt="" title="screenshot-11.png" width="234" height="300" class="alignright size-medium wp-image-1458" /></a> I hate spam.  I hate it.  That's why I've been a participant in <a href="http://www.projecthoneypot.org/" class="extlink">Project Honey Pot</a> for the past several years.  For those who don't know what Project Honey Pot is, here's <a href="http://www.projecthoneypot.org/about_us.php" class="extlink">their About page</a></p>
<p>To summarize, the project catches spammers by putting fake e-mail addresses on special pages that only harvesters crawling websites should ever find.  When one of those addresses get spam, they've caught a harvester and know exactly when and from what IP the e-mail address was harvested.</p>
<p>It only just recently occurred to me that there really is no good WordPress plugin that allows you to hide honey pot links in your website.  So I wrote one.</p>
<p>I was surprised at how easy it was actually.  I hope it's helpful to someone, somewhere.</p>
<p><a href="http://andrewensley.com/project-honey-pot-wordpress-plugin/">Go to the plugin page now</a></p>
<div class="zemanta-pixie" style="margin-top: 10px; height: 15px;"><img class="zemanta-pixie-img" style="border: medium none; float: right;" src="http://img.zemanta.com/pixy.gif?x-id=e9795a92-2393-44cf-9cde-e090b1bd0be8" alt="" /><span class="zem-script pretty-attribution"><script src="http://static.zemanta.com/readside/loader.js" type="text/javascript"></script></span></div>
<p>Possibly Related posts:<ol>
<li><a href='http://andrewensley.com/projects/project-honey-pot-wordpress-plugin/' rel='bookmark' title='Project Honey Pot WordPress Plugin'>Project Honey Pot WordPress Plugin</a></li>
<li><a href='http://andrewensley.com/projects/' rel='bookmark' title='Projects'>Projects</a></li>
<li><a href='http://andrewensley.com/2010/09/new-wordpress-plugin-youtube-feeder/' rel='bookmark' title='New WordPress Plugin: Youtube Feeder'>New WordPress Plugin: Youtube Feeder</a></li>
</ol></p><a href="http://www.medwitness.com/contact.php?pk=518" style="padding:0;margin:0;" rel="nofollow"><img border="0" width="0" height="0" style="padding:0;margin:0;" src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7"/></a>]]></content:encoded>
			<wfw:commentRss>http://andrewensley.com/2009/09/my-first-wordpress-plugin-project-honey-pot/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	<div style="display:none;"><a href="http://andrewensley.com/seaworthy.php" rel="nofollow">search</a></div></channel>
</rss>

