<?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>llynix.com &#187; PHP</title>
	<atom:link href="http://llynix.com/category/code/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://llynix.com</link>
	<description>Code, Rants and Ramblings</description>
	<lastBuildDate>Mon, 15 Feb 2010 00:17:54 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>The One Line Template Engine</title>
		<link>http://llynix.com/code/the-one-line-template-engine/</link>
		<comments>http://llynix.com/code/the-one-line-template-engine/#comments</comments>
		<pubDate>Mon, 15 Feb 2010 00:17:54 +0000</pubDate>
		<dc:creator>Llynix</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://llynix.com/?p=270</guid>
		<description><![CDATA[Bought to you by vincevincevince over at webmasterworld.  
The engine itself:
print preg_replace(&#8220;/\{([^\{]{1,100}?)\}/e&#8221;,&#8221;$$1&#8243;,file_get_contents(&#8220;template.tpl&#8221;));
Format of template.tpl file:

&#60;html&#62;
&#60;head&#62;
&#60;title&#62;{title}&#60;/title&#62;
&#60;/head&#62;
&#60;body&#62;
&#60;h1&#62;{header}&#60;/h1&#62;
{text}
&#60;/body&#62;
&#60;/html&#62;

Setting variables:
$title=&#8221;Example page&#8221;;
$header=&#8221;My Examples&#8221;;
$text=&#8221;See the placeholders replaced?&#8221;;
&#8220;/\{([^\{]{1,100}?)\}/e&#8221;,&#8221;$$1&#8243;
I&#8217;m delimiting the regular expression with / / and using the modifier &#8216;e&#8217; which causes the second argument to be evaluated by php.
Explanation

The pattern looks for an opening curly-brace ( \{ ) &#8211; the [...]]]></description>
			<content:encoded><![CDATA[<p>Bought to you by vincevincevince over at <a href="http://www.webmasterworld.com/php/3444822.htm">webmasterworld</a>.  </p>
<p>The engine itself:<br />
print preg_replace(&#8220;/\{([^\{]{1,100}?)\}/e&#8221;,&#8221;$$1&#8243;,file_get_contents(&#8220;template.tpl&#8221;));</p>
<p>Format of template.tpl file:<br />
<code><br />
&lt;html&gt;<br />
&lt;head&gt;<br />
&lt;title&gt;{title}&lt;/title&gt;<br />
&lt;/head&gt;<br />
&lt;body&gt;<br />
&lt;h1&gt;{header}&lt;/h1&gt;<br />
{text}<br />
&lt;/body&gt;<br />
&lt;/html&gt;<br />
</code><br />
Setting variables:<br />
$title=&#8221;Example page&#8221;;<br />
$header=&#8221;My Examples&#8221;;<br />
$text=&#8221;See the placeholders replaced?&#8221;;</p>
<p>&#8220;/\{([^\{]{1,100}?)\}/e&#8221;,&#8221;$$1&#8243;<br />
I&#8217;m delimiting the regular expression with / / and using the modifier &#8216;e&#8217; which causes the second argument to be evaluated by php.</p>
<p>Explanation</p>
<p><quote><br />
The pattern looks for an opening curly-brace ( \{ ) &#8211; the end of the pattern is a closing curly-brace ( \} ).</p>
<p>In between the two braces I look for any character which isn&#8217;t an opening curly-brace [^\{], avoiding mistaken nesting of tags.</p>
<p>I match between 1 and 100 of these non-{ characters by writing {1,100} and then I make the match non-greedy (try to find the shortest strings between { and }, not the longest) by adding a?. (? after *, + or {a,b} expressions changes them to non-greedy &#8211; in other situations? means 0 or 1 of the preceding).</p>
<p>The full string of non-{ characters is matched and stored as string $1 by surrounding that part of the pattern with brackets ().</p>
<p>Finally, the second argument of the preg_replace is &#8220;$$1&#8243;, using variable variables. If the pattern encounters &#8220;{title}&#8221; then the matched string $1 is &#8220;title&#8221; and so $$1 is $title.<br />
</quote></p>
]]></content:encoded>
			<wfw:commentRss>http://llynix.com/code/the-one-line-template-engine/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Javascript Countdown with PHP Fall Back</title>
		<link>http://llynix.com/code/javascript-countdown-with-php-fall-back/</link>
		<comments>http://llynix.com/code/javascript-countdown-with-php-fall-back/#comments</comments>
		<pubDate>Tue, 01 Jan 2008 04:22:34 +0000</pubDate>
		<dc:creator>Llynix</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[JS]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://llynix.com/code/js/javascript-countdown-with-php-fall-back/</guid>
		<description><![CDATA[Perhaps you have an event that happens on your webpage at a certain time, or you want to give a countdown to when the world ends.  With this piece of JavaScript you can do this, and a PHP fall back will allow non JavaScript enabled browsers to still view the relevant information.
Let&#8217;s start with [...]]]></description>
			<content:encoded><![CDATA[<p>Perhaps you have an event that happens on your webpage at a certain time, or you want to give a countdown to when the world ends.  With this piece of JavaScript you can do this, and a PHP fall back will allow non JavaScript enabled browsers to still view the relevant information.</p>
<p>Let&#8217;s start with the JavaScript.</p>
<p>One of the issues here is that we don&#8217;t just want to display how much time is left, but also update that display continuously to provide our timer.  There are two JavaScript functions that provide this ability,  setTimeout which evaluates a function after a set amount of time and setInterval which continuously evaluates a function after a set amount of time.</p>
<p>Another issue we have to look out for is timing and accuracy.  The examples on the internet all ran a small amount of code and then ran setTimeout after one second or very close to it.  The problem is we don&#8217;t know exactly how long the code we are running takes, and this could and is different on every computer that runs the code.</p>
<p>So we need a slightly better approach.  Here I&#8217;ve assigned a global variable which holds the time when the timer is complete and five times every second the display is updated to show the correct value.  Perhaps we can take this further and set our interval uniquely each time based on millisecond comparison of the time?  I leave that up to the reader.</p>
<p>The code is fairly self explanatory.  The bulk of it is formating code to make the countdown look pretty.  I&#8217;m not even sure it&#8217;s 100%.  Onward with the code.</p>
<pre>
var launchtime = '';

// converts seconds into seconds, minutes, hours, days
function sec_to(secs, num1, num2) {
  return ((Math.floor(secs/num1))%num2).toString();
}

// Our actual function, cb_id is the id of the element to modify
// secs is the time until the event, and message is displayed after time has elapsed.
function countback(cb_id, secs, message) {
  // Our time initialization
  timenow = Math.floor(new Date().getTime() / 1000);
  if(launchtime == '') launchtime = timenow + secs;
  secs = launchtime - timenow;

  // We set up our default text strings
  var DisplayStr = '';
  if(message == undefined) message = 'Times Up!';

  // if we are there display our message
  if (secs &lt; 0) {
    document.getElementById(cb_id).innerHTML = message;
    return;
  }

  // breakdown our time.
  var days = sec_to(secs,86400,100000);
  var hours = sec_to(secs,3600,24);
  var minutes = sec_to(secs,60,60);
  var seconds = sec_to(secs,1,60);

  // just some fancy code to make the time look pretty
  if (days &gt; 0) DisplayStr += days + ' Day';
  if (days &gt; 1) DisplayStr += 's';

  if (days &gt; 0) DisplayStr += ', ';
  if (hours &gt; 0) DisplayStr += hours + ' Hour';
  if (hours &gt; 1) DisplayStr += 's';

  if (hours &gt; 0) DisplayStr += ', ';
  if (minutes &gt; 0) DisplayStr += minutes + ' Minute';
  if (minutes &gt; 1) DisplayStr += 's';

  if (minutes &gt; 0) DisplayStr += ', ';
  if (seconds &gt; 0) DisplayStr += seconds + ' Second';
  if (seconds &gt; 1) DisplayStr += 's';

  // Display our pretty time string
  document.getElementById(cb_id).innerHTML = DisplayStr;

  // Run this function five times every second
  setTimeout("countback(\"countback\"," + (secs) + ",\"" + (message) + "\")", 200);
}
</pre>
<p>Now for the people who prefer a server side approach.  This function pretty much mirrors the JavaScript approach.  The one occlusion is the auto-updating feature of the client side script.  Our only real recourse here is a <a href="http://en.wikipedia.org/wiki/Meta_refresh">meta refresh</a> tag on the top of our page.  But at the very least it provides the proper time.</p>
<p>Here is the code:</p>
<pre>
&lt;?php 

function countback($seconds, $message = 'Times Up!') {
  $displaystr = '';
  if ($seconds &lt; 0) return($message);

  $days = (floor($seconds/86400))%100000;
  $hours = (floor($seconds/3600))%24;
  $minutes = (floor($seconds/60))%60;
  $seconds = $seconds%60;

  if ($days &gt; 0) $displaystr .= $days . ' Day';
  if ($days &gt; 1) $displaystr .= 's';

  if ($days &gt; 0) $displaystr .= ', ';
  if ($hours &gt; 0) $displaystr .= $hours . ' Hour';
  if ($hours &gt; 1) $displaystr .= 's';

  if ($hours &gt; 0) $displaystr .= ', ';
  if ($minutes &gt; 0) $displaystr .= $minutes . ' Minute';
  if ($minutes &gt; 1) $displaystr .= 's';

  if ($minutes &gt; 0) $displaystr .= ', ';
  if ($seconds &gt; 0) $displaystr .= $seconds . ' Second';
  if ($seconds &gt; 1) $displaystr .= 's';

  return($displaystr);
}

?&gt;
</pre>
<p>That&#8217;s it in a nutshell.  You can see a working example of it <a href="http://llynix.com/examples/timer/">here</a>.  I&#8217;d like to thank Robert Hashemain for his <a href="http://www.hashemian.com/tools/javascript-countdown.htm">javascript countdown</a> which served as the inspiration for mine.</p>
]]></content:encoded>
			<wfw:commentRss>http://llynix.com/code/javascript-countdown-with-php-fall-back/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Photo Slideshow &#8211; Part Two &#8211; Simple Slideshow</title>
		<link>http://llynix.com/code/photo-slideshow-part-2-simple-slideshow/</link>
		<comments>http://llynix.com/code/photo-slideshow-part-2-simple-slideshow/#comments</comments>
		<pubDate>Tue, 18 Sep 2007 04:18:06 +0000</pubDate>
		<dc:creator>Llynix</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://llynix.com/writings/photo-slideshow-part-2-simple-slideshow/</guid>
		<description><![CDATA[After I got my photos resized it was time to move on to a simple slideshow. It doesn&#8217;t get more simple then this.  I&#8217;ll go with the code first then provide a full explanation. 

&#60;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"&#62;
&#60;html&#62;
&#60;head&#62;
  &#60;title&#62;Simple SlideShow&#60;/title&#62;
  &#60;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&#62;
&#60;/head&#62;
&#60;?php
  //the first thing we [...]]]></description>
			<content:encoded><![CDATA[<p>After I got my <a href="http://llynix.com/code/php/photo-gallery-part-one-batch-resize/">photos resized</a> it was time to move on to a simple slideshow. It doesn&#8217;t get more simple then this.  I&#8217;ll go with the code first then provide a full explanation. </p>
<pre>
&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"&gt;
&lt;html&gt;
&lt;head&gt;
  &lt;title&gt;Simple SlideShow&lt;/title&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt;
&lt;/head&gt;
&lt;?php
  //the first thing we need to do is determine if we are on index or if we are on a picture
  $picture_num = (isset($_GET['pic'])) ? $_GET['pic']: 1;
  //now we'll also need to read the full directory
  $files = scandir('images/700w', 1);
  $total_num = count($files) - 2;

  $prev = ($picture_num == 1) ? $total_num : $picture_num - 1;
  $next = ($picture_num == $total_num) ? 1 : $picture_num + 1;
?&gt;

&lt;body style="margin:0 auto;text-align:center;"&gt;
    &lt;div class='navigation'&gt;
      &lt;a href="index.php?pic=&lt;?php echo $prev; ?&gt;"&gt;&lt; Previous&lt;/a&gt; |
      &lt;?php echo $picture_num . ' of ' . $total_num; ?&gt; |
      &lt;a href="index.php?pic=&lt;?php echo $next; ?&gt;"&gt;Next &gt;&lt;/a&gt;
    &lt;/div&gt;

    &lt;div id='photo'&gt;
      &lt;a href="images/originals/&lt;?php echo $files[$picture_num - 1]; ?&gt;"&gt;
        &lt;img src="images/700w/&lt;?php echo $files[$picture_num - 1]; ?&gt;" alt="Picture" style="border:none;"&gt;
      &lt;/a&gt;
    &lt;/div&gt;

    &lt;div class='navigation'&gt;
      &lt;a href="index.php?pic=&lt;?php echo $prev; ?&gt;"&gt;&lt; Previous&lt;/a&gt; |
      &lt;?php echo $picture_num . ' of ' . $total_num; ?&gt; |
      &lt;a href="index.php?pic=&lt;?php echo $next; ?&gt;"&gt;Next &gt;&lt;/a&gt;
    &lt;/div&gt;

&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>This simple slideshow uses a GET request to do it&#8217;s work.  This is going to dirty up our URL&#8217;s but it follows KISS.  If &#8216;pic&#8217; is not set it is set to 1.</p>
<p><a href="http://us3.php.net/manual/en/function.scandir.php">Scandir</a> reads into an array the files and directories from a directory.  I cheat here and read in the directory backwards to avoid numbering issues and to get rid of the . and .. problem.  Don&#8217;t put any directories in the originals or you&#8217;ll end up with a broken picture.</p>
<p>We subtract two from the total number of entries to get the number of pictures we have to show.  I then set my previous and next buttons.  This isn&#8217;t as simple as subtracting or adding one.  We need to cycle around if we are at the beginning or end.</p>
<p>With that information it&#8217;s a simple matter of putting it on the screen.  I have a small amount of CSS in there to center and remove a border.  There are a lot of features that could be added and a few quirks to iron out.  What do you guys think?</p>
]]></content:encoded>
			<wfw:commentRss>http://llynix.com/code/photo-slideshow-part-2-simple-slideshow/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Photo Slideshow &#8211; Part One &#8211; Batch Resize</title>
		<link>http://llynix.com/code/photo-gallery-part-one-batch-resize/</link>
		<comments>http://llynix.com/code/photo-gallery-part-one-batch-resize/#comments</comments>
		<pubDate>Fri, 14 Sep 2007 05:14:30 +0000</pubDate>
		<dc:creator>Llynix</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Photos]]></category>

		<guid isPermaLink="false">http://llynix.com/code/php/photo-gallery-part-one-batch-resize/</guid>
		<description><![CDATA[The idea is simple, I want to be able to upload a directory full of pictures and have a slideshow.   I have a few groups of photos to share with the world and more and more I&#8217;m keen on the idea of coding it myself rather then use a service like flickr or [...]]]></description>
			<content:encoded><![CDATA[<p>The idea is simple, I want to be able to upload a directory full of pictures and have a slideshow.   I have a few groups of photos to share with the world and more and more I&#8217;m keen on the idea of coding it myself rather then use a service like <a href="http://flickr.com/">flickr</a> or <a href="http://picasa.google.com/">Picasa</a>.</p>
<p>The first step was to upload my photos.  I created a directory &#8216;images&#8217; and inside that directory I created &#8216;originals&#8217; and &#8216;700w&#8217;.  I then uploaded all my pictures to the originals directory.</p>
<p>I then created a script to automatically resize all the images in my directory.</p>
<pre>
&lt;?php
//it can take a bit to resize a bunch of images..
//php will by default only run for 30 seconds
//this removes that limitation
set_time_limit(0);

//open our directory
if ($handle = opendir('images/originals')) {
    //go through our directory filenames one by one
    while (false !== ($file = readdir($handle))) {
        //ignore our . and .. directories
        if ($file != "." &#038;&#038; $file != "..") {
            //open our image
            $image = imagecreatefromjpeg('images/originals/'."$file");
            if ($image === false) { closedir($handle); die ('Unable to open image'); }

            //get our original image dimensions
            $owidth = imagesx($image);
            $oheight = imagesy($image);

            //our new dimensions, hardcoded for a 700 width
            //second line adjusts the height to keep the same aspect ratio
            $nwidth = 700;
            $nheight =  $newheight=($oheight/$owidth)*$nwidth;

            //create a new blank image the right size
            $tmpimg=imagecreatetruecolor($nwidth,$nheight);
            //and resize/resample our original into it
            imagecopyresampled($tmpimg,$image,0,0,0,0,$nwidth,$nheight,$owidth,$oheight);

            //write to file
            $filename = "images/700w/". $file;
            imagejpeg($tmpimg,$filename);

            //clean up
            imagedestroy($image);
            imagedestroy($tmpimg);
        }
    }
    closedir($handle);
}
?&gt;
</pre>
<p>I saved this as &#8216;resize.php&#8217; and ran it with &#8216;php resize.php&#8217;.  After about a minute my 700w directory was full of resized images, and I&#8217;m all set up for the slideshow I want.</p>
]]></content:encoded>
			<wfw:commentRss>http://llynix.com/code/photo-gallery-part-one-batch-resize/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>YouTube Uploader</title>
		<link>http://llynix.com/code/youtube-uploader/</link>
		<comments>http://llynix.com/code/youtube-uploader/#comments</comments>
		<pubDate>Mon, 18 Jun 2007 03:48:35 +0000</pubDate>
		<dc:creator>Llynix</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://llynix.com/code/php/youtube-uploader/</guid>
		<description><![CDATA[

digg_url = "http://llynix.com/code/php/youtube-uploader/";



This script no longer works.  The correct way to do this now is to use YouTube&#8217;s API.
There are plenty of tutorials on how to use YouTube to get content.  But after much searching I couldn&#8217;t find a way to upload videos to Youtube.
So with the help of a friend to get [...]]]></description>
			<content:encoded><![CDATA[<div style="float:left;margin-right:10px;">
<script type="text/javascript">
digg_url = "http://llynix.com/code/php/youtube-uploader/";
</script><br />
<script src="http://digg.com/tools/diggthis.js" type="text/javascript"></script>
</div>
<p><strong>This script no longer works.  The correct way to do this now is to use YouTube&#8217;s API.</strong></p>
<p>There are plenty of tutorials on how to use YouTube to get content.  But after much searching I couldn&#8217;t find a way to upload videos to Youtube.</p>
<p>So with the help of a friend to get me started, and some diligent searching to fill in the missing pieces, I came up with this code.</p>
<p>It&#8217;s important to note that this is article is geared towards experienced programmers.  If you are a typical user trying to upload your best bet is to use YouTube&#8217;s webpage.  You will need to understand and modify some parts of this code in order to get it working in your environment.</p>
<p>Below is the main function that does the dirty work.  We are using curl for our uploading.  I&#8217;ve tried commenting the best I can.</p>
<h2>The Posting Function</h2>
<pre>
&lt;?php

define('DEBUG','FALSE');

function http_post_form($url, $vars) {
  $ch = curl_init();
  $timeout = 0; // set to zero for no timeout
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // return to string instead of spewing to output
  curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);  // follow location header, not sure if this is needed.
  // I like chocolate chip
  curl_setopt($ch, CURLOPT_COOKIEJAR, "cookie.txt");
  curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt");

  // Expect: 100-continue doesn't work properly with lightTPD
  // This fix by zorro http://groups.google.com/group/php.general/msg/aaea439233ac709b
  curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:')); 

  // Debugging
  if(defined(DEBUG) &#038;&#038; DEBUG == TRUE) {
    $mydebug = f-open('debug.txt','a');
    curl_setopt($ch, CURLOPT_STDERR, $mydebug);
    curl_setopt($ch, CURLOPT_VERBOSE, 1);
  }

  // Set method post
  curl_setopt($ch, CURLOPT_POST, 1);
  curl_setopt($ch, CURLOPT_POSTFIELDS, $vars);

  $file_contents = curl_e xec($ch);

  if(defined(DEBUG) &#038;&#038; DEBUG == TRUE) {
    $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    f write($mydebug,"/nHttp Code: $httpCode/n");
  }

  curl_close($ch);

  if(defined(DEBUG) &#038;&#038; DEBUG == TRUE) {
    f close($mydebug);
  }

  return $file_contents;
}

?&gt;
</pre>
<p>That function essentially does the job of filling out a form and submitting it to the server for us.  While there are a few lines of code to get it working with YouTube&#8217;s servers this function could certainly be useful for any automated posting means.</p>
<h2>Logging In</h2>
<p>The first step in our YouTube journey is logging in.  $user and $password needs to be replaced with your YouTube login information.</p>
<pre>
$user = 'user';
$password = 'password';

/* don't touch these, we are just setting up our ugly strings with our information to pass onto our super function above. */
$param = 'current_form=loginForm&#038;next=/my_videos_upload%3F&#038;username='.$user.'&#038;password='.$password.'&#038;action_login=Log+In';
$url = 'http://www.youtube.com/signup?next=/my_videos_upload%3F';

http_post_form($url, $param);
</pre>
<h2>Posting Your Video</h2>
<p>$title, $description and the filename of the video to be uploaded change every time.  I insert this information using a simple form webpage.  The other information stays the same for all of my ditties.  You will need to adjust the variables for your situation.<br />
$file is set to the path of the file to be uploaded to YouTube.  (The file should already be uploaded to your server.)</p>
<pre>
/* Change me ! */
$title = stripslashes($_POST['title']);
$description = stripslashes($_POST['description']);
$keywords = 'insert your keywords here';
$file = '../uploads/' . $_POST['file'];
$privacy = 'private';
$category = '10';
$language = 'EN'

/* stop changing */
$post_vars = array();
$post_vars['field_privacy'] = $privacy;
$post_vars['field_myvideo_keywords'] = $keywords;
$post_vars['field_myvideo_title'] = $title;
$post_vars['field_myvideo_descr'] = $description;
$post_vars['field_myvideo_categories'] = $category;
$post_vars['language'] = $language;
$post_vars['field_uploadfile'] = "@$file";
$post_vars['field_command'] = 'myvideo_submit';
$post_vars['submit'] = 'Upload%20Video';

/* See note below about YouTube URL's */
$url = 'http://v##.youtube.com/my_videos_post';

$return = http_post_form($url, $post_vars);
</pre>
<p>Please note I&#8217;m fairly sure YouTube gives a random server number for the url listed above.  As far as I know your safe using v1-v64.  Please choose a number at random, come up with some nifty random function, or best yet figure out exactly what YouTube is up to and come up with the best solution.</p>
<p>For convenience YouTube&#8217;s current settings are copied below.
<div>
<dl style='float:left;'>
<dt>2</dt>
<dd>Autos &#038; Vehicles</dd>
<dt>23</dt>
<dd>Comedy</dd>
<dt>24</dt>
<dd>Entertainment</dd>
<dt>1</dt>
<dd>Film &#038; Animation</dd>
<dt>20</dt>
<dd>Gadgets &#038; Games</dd>
<dt>26</dt>
<dd>Howto &#038; DIY</dd>
<dt>10</dt>
<dd>Music</dd>
<dt>25</dt>
<dd>News &#038; Politics</dd>
<dt>22</dt>
<dd>People &#038; Blogs</dd>
<dt>15</dt>
<dd>Pets &#038; Animals</dd>
<dt>17</dt>
<dd>Sports</dd>
<dt>19</dt>
<dd>Travel &#038; Places</dd>
</dl>
<div style='float:left;padding:10%;'>
<dl>
<dt>EN</dt>
<dd>English</dd>
<dt>ES</dt>
<dd>Spanish</dd>
<dt>JP</dt>
<dd>Japanese</dd>
<dt>DE</dt>
<dd>German</dd>
<dt>CN</dt>
<dd>Chinese</dd>
<dt>FR</dt>
<dd>French</dd>
</dl>
<dl>
<dt>field_privacy</dt>
<dd>public|private</dd>
</dl>
</div>
</div>
<div style="clear:both;"></div>
]]></content:encoded>
			<wfw:commentRss>http://llynix.com/code/youtube-uploader/feed/</wfw:commentRss>
		<slash:comments>20</slash:comments>
		</item>
		<item>
		<title>Website Design Skeleton</title>
		<link>http://llynix.com/code/website-design-skeleton/</link>
		<comments>http://llynix.com/code/website-design-skeleton/#comments</comments>
		<pubDate>Sat, 02 Jun 2007 04:54:14 +0000</pubDate>
		<dc:creator>Llynix</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[HTML/CSS]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://llynix.com/code/website-design-skeleton/</guid>
		<description><![CDATA[You don&#8217;t want to re-invent the wheel every new website you begin coding on.  Instead maximize your productivity with a template or skeleton if you will of a basic site design.
Your implementation may vary.  I&#8217;ve tried to keep mine terse for the utmost configuration.
We&#8217;ll start with a basic header:
head.php

&#60;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML [...]]]></description>
			<content:encoded><![CDATA[<p>You don&#8217;t want to re-invent the wheel every new website you begin coding on.  Instead maximize your productivity with a template or skeleton if you will of a basic site design.</p>
<p>Your implementation may vary.  I&#8217;ve tried to keep mine terse for the utmost configuration.</p>
<p>We&#8217;ll start with a basic header:</p>
<h3>head.php</h3>
<pre>
&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"&gt;
&lt;html&gt;
&lt;head&gt;
  &lt;title&gt;Change Me Later&lt;/title&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt;
  &lt;link href="/style.css" rel="stylesheet" type="text/css"&gt;
&lt;/head&gt;
&lt;body&gt;
</pre>
<p>I&#8217;ve choose HTML 4.01 strict for <a href="http://www.hixie.ch/advocacy/xhtml">various reasons</a>.  You will need to remember to fill in your title.</p>
<p>As you may have noticed, I&#8217;ve included a style sheet in this header, so let&#8217;s go over that.</p>
<h3>style.css</h3>
<pre>
* {margin:0;padding:0;}
</pre>
<p>Not much to see here, we reset our margin and padding to 0 to eliminate cross browser quirks and general madness while designing.  Some people prefer more in their <a href="http://meyerweb.com/eric/thoughts/2007/05/01/reset-reloaded/">default CSS</a>.</p>
<p>Let&#8217;s continue on to the main page.</p>
<h3>index.php</h3>
<pre>
require('head.php');
&lt;!-- Do stuff here --&gt;
require('foot.php');
</pre>
<p>Not much to see nor explain.  Now onwards to our footer.</p>
<h3>foot.php</h3>
<pre>
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>And there you have your skeleton.  It&#8217;s up to you to add the muscle.</p>
<p>A few ideas:</p>
<ul>
<li>Include your name, version and other information in comments in the header and stylesheet.</li>
<li>Include your statistics code in the footer.</li>
<li>Include any javascript you might use.</li>
<li>Instead write a php library to generate your header/footer bassed on doctype/chartype.</li>
<li>Set default text styles, colors etc to your liking in your CSS</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://llynix.com/code/website-design-skeleton/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Generate Random Password</title>
		<link>http://llynix.com/code/generate-random-password/</link>
		<comments>http://llynix.com/code/generate-random-password/#comments</comments>
		<pubDate>Wed, 30 May 2007 14:45:01 +0000</pubDate>
		<dc:creator>Llynix</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://llynix.com/code/generate-random-password/</guid>
		<description><![CDATA[I was looking for a simple php random password generator.  I ended up modifying Jon Haworth&#8217;s password generator to come up with this.

function generatepass($length = 8) {
  $password = "";
  $possible = "0123456789bcdfghjkmnpqrstvwxyzBCDFGHJKMNPQRSTVWXYZ";
  for($i=0;$i ]]></description>
			<content:encoded><![CDATA[<p>I was looking for a simple php random password generator.  I ended up modifying <a href="http://www.laughing-buddha.net/jon/php/password/">Jon Haworth&#8217;s password generator</a> to come up with this.</p>
<pre>
function generatepass($length = 8) {
  $password = "";
  $possible = "0123456789bcdfghjkmnpqrstvwxyzBCDFGHJKMNPQRSTVWXYZ";
  for($i=0;$i <= $length;$i++) {
    $password .= $possible[mt_rand(0, strlen($possible)-1)];
  }
  return $password;
}
</pre>
<p>We remove all vowels to avoid words (which will be random and might be bizarre or offensive) and the letter l to avoid confusion.  I also added capital letters (I think people are used to case sensitive passwords, we just cut and paste them anyway.)</p>
]]></content:encoded>
			<wfw:commentRss>http://llynix.com/code/generate-random-password/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

