<?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>DJS Web Design</title>
	<atom:link href="http://djswebdesign.com/feed" rel="self" type="application/rss+xml" />
	<link>http://djswebdesign.com</link>
	<description>Freelance Web Designer</description>
	<lastBuildDate>Wed, 16 May 2012 12:08:09 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Creating a Space Delimited Text File</title>
		<link>http://djswebdesign.com/php/creating-a-space-delimited-text-file.html</link>
		<comments>http://djswebdesign.com/php/creating-a-space-delimited-text-file.html#comments</comments>
		<pubDate>Tue, 15 May 2012 20:23:09 +0000</pubDate>
		<dc:creator>Admin</dc:creator>
				<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://djswebdesign.com/?p=195</guid>
		<description><![CDATA[A few days ago I had to export data to create a space delimited text file. A space delimited text file is a flat data file similar to a .csv. The big difference is a space delimited file does not separate data with a comma, tab or other delimiter. A space delimited file simply relies [...]]]></description>
			<content:encoded><![CDATA[<p>A few days ago I had to export data to create a <strong>space delimited</strong> text file. A space delimited text file is a flat data file similar to a .csv. The big difference is a space delimited file does not separate data with a comma, tab or other delimiter. A space delimited file simply relies on SPACING as the delimiter. For example, lets say we have a csv file with the following fruit related data columns FruitName, FruitColor, FruitTaste.  Your csv file might look something like this.</p>
<p>&#8220;apple&#8221;,&#8221;red&#8221;,&#8221;good&#8221;<br />
&#8220;banana&#8221;,&#8221;yellow&#8221;,&#8221;yummy&#8221;<br />
&#8220;water melon&#8221;,&#8221;green&#8221;,&#8221;delicious&#8221;</p>
<p>Well with a space delimited file you would have a defined length for each data column.  Lets say FruitName = 12 , FruitColor = 10, FruitTaste = 10.  This would give each row in your data file a total length of 32 spaces and would look something like this.</p>
<p>apple       red       good<br />
banana      yellow    yummy<br />
water melon green     delicious</p>
<p>If you copy the three lines of text above and past it into a .txt file it will line up into nice columns.</p>
<p>While there were quite a few resources showing how to create a tab delimited file or a comma delimited file there was virtually nothing out there discussing a space delimited file.  So after a few attempts and few really ugly looking text files here is what I came up with.</p>
<pre class="brush:php">

<?php
	/* You should already be connected to you data base at this point */
	$file = fopen("FileName.txt", "w");
	$sqlExport = "SELECT * FROM `TableName`";
		$results = mysql_query($sqlExport,$DBcon) or die("Error in query: $sqlExport " . mysql_error());
		while($row = mysql_fetch_array($results)) {
			$lenField1 = strlen($row[0]);
			$fieled1 = $row[0];
				While($lenParcel < 15) { /* 15 is the total length for this field */
					$field1 = substr_replace($field1,' ',$lenField1);
					$lenField1++;
				}
			$lenField2 = strlen($row[1]);
			$field2 = $row[1];
				While($lenField2 < 24) {  /* 24 is the total length for this field */
					$field2 = substr_replace($field2,' ',$lenField2);
					$lenField2++;
				}
			$lenField3 = strlen($row[2]);  /* All the data in this col was only 3 spaces */
			$field3 = $row[2];

			 $row_to_export = "$field1$field2$field3\r\n"; /* the \r\n echos a CR and New Line  */
			 fwrite($file, $row_to_export);
		}
	mysql_close ($DBcon); /* Close Database Connection */
	fclose($file);
?>
</pre>
<p>That is pretty much it!  The script above will export data to a space delimited text file name &#8216;FileName.txt&#8217;  The file will be created in the same folder where the script is executed.  Feel free to comment and offer suggestions.</p>
]]></content:encoded>
			<wfw:commentRss>http://djswebdesign.com/php/creating-a-space-delimited-text-file.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using PHP for Year in Copyright</title>
		<link>http://djswebdesign.com/php/using-php-for-year-in-copyright.html</link>
		<comments>http://djswebdesign.com/php/using-php-for-year-in-copyright.html#comments</comments>
		<pubDate>Mon, 05 Dec 2011 16:17:57 +0000</pubDate>
		<dc:creator>Admin</dc:creator>
				<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://djswebdesign.com/?p=12</guid>
		<description><![CDATA[Wow 2011 has really flown by.  Now that 2012 is almost here it&#8217;s time to start changing copyright info in the footer of your site.  Here is quick and easy way to make sure your copyright line always contains the correct year.  The code below pertains to PHP. It&#8217;s Just that easy. Now you can [...]]]></description>
			<content:encoded><![CDATA[<p>Wow 2011 has really flown by.  Now that 2012 is almost here it&#8217;s time to start changing copyright info in the footer of your site.  Here is quick and easy way to make sure your copyright line always contains the correct year.  The code below pertains to PHP.</p>
<pre class="brush:php">
<?php echo date("Y"); ?>
</pre>
<p>It&#8217;s Just that easy. Now you can go and update your copyright info for the last time!</p>
]]></content:encoded>
			<wfw:commentRss>http://djswebdesign.com/php/using-php-for-year-in-copyright.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

