<?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"
	>

<channel>
	<title>A Web Developers Blog</title>
	<atom:link href="http://blog.jrtashjian.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.jrtashjian.com</link>
	<description>Web Application Design and Development</description>
	<pubDate>Thu, 20 Nov 2008 01:44:12 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.3</generator>
	<language>en</language>
			<item>
		<title>Code Snippet: Limit Words in a String</title>
		<link>http://blog.jrtashjian.com/2008/11/10/code-snippet-limit-words-in-a-string/</link>
		<comments>http://blog.jrtashjian.com/2008/11/10/code-snippet-limit-words-in-a-string/#comments</comments>
		<pubDate>Mon, 10 Nov 2008 09:36:00 +0000</pubDate>
		<dc:creator>jrtashjian</dc:creator>
		
		<category><![CDATA[Code Snippets]]></category>

		<category><![CDATA[arrays]]></category>

		<category><![CDATA[function]]></category>

		<category><![CDATA[php]]></category>

		<category><![CDATA[strings]]></category>

		<guid isPermaLink="false">http://blog.jrtashjian.com/?p=16</guid>
		<description><![CDATA[While developing websites, I&#8217;ve frequently run into clients who would like a news system integrated on their site. A news system consists of a list of articles, usually a summary at first, and when an article has been selected, the full article is displayed. So, how do you extract the summary from the content without [...]]]></description>
			<content:encoded><![CDATA[<p>While developing websites, I&#8217;ve frequently run into clients who would like a news system integrated on their site. A news system consists of a list of articles, usually a summary at first, and when an article has been selected, the full article is displayed. So, how do you extract the summary from the content without duplicating content?</p>
<p>If you wanted to do this effect quickly, you could just use the function <a href="http://php.net/substr">substr()</a>. However, the <a href="http://php.net/substr">substr()</a> function only limits the number of characters being displayed. The returned result would be an excerpt of text that may or may not have the ending word cut-off.</p>
<p>The purpose behind this function is to limit the number of words displayed in such a way that the ending word is not cut-off. Personally, I think this small change makes the site look a little nicer.</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #0000ff; font-style: italic;">/**
 * Limits the number of words in a string
 */</span>
<span style="color: #000000; font-weight: bold;">function</span> limit_words<span style="color: #009900;">&#40;</span><span style="color: #000088;">$string</span><span style="color: #339933;">,</span> <span style="color: #000088;">$word_limit</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000088;">$words</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot; &quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$string</span><span style="color: #009900;">&#41;</span>;
<span style="color: #b1b100;">return</span> <span style="color: #990000;">implode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot; &quot;</span><span style="color: #339933;">,</span><span style="color: #990000;">array_splice</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$words</span><span style="color: #339933;">,</span><span style="color:#800080;">0</span><span style="color: #339933;">,</span><span style="color: #000088;">$word_limit</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>To use this function, pass the text you would like to extract the excerpt from, as $string. Then, set the number of words you would like to display as $word_limt. The function will return the excerpt as a string.</p>
<p>The function separates <small>[<a href="http://php.net/explode">explode()</a>]</small> the string where it finds a space, therefore separating each word. Each word is put into an array called $words. We then cut out <small>[<a href="http://php.net/array_splice">array_splice()</a>]</small> the excerpt using the number of words we would like to display ($word_limit) starting from the beginning. With the excerpt extracted from the full text, we then recreate <small>[<a href="http://php.net/implode">implode()</a>]</small> the string by adding spaces after each key (word) in the array.</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># Example Usage</span>
<span style="color: #000088;">$content</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.&quot;</span>;
<span style="color: #990000;">echo</span> limit_words<span style="color: #009900;">&#40;</span><span style="color: #000088;">$content</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">20</span><span style="color: #009900;">&#41;</span>;</pre></div></div>

<p>The above example would output this result:</p>
<p><code>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut</code></p>
<p>Simple function, Nice results. Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jrtashjian.com/2008/11/10/code-snippet-limit-words-in-a-string/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Planning a Web Application</title>
		<link>http://blog.jrtashjian.com/2008/09/16/planning-a-web-application/</link>
		<comments>http://blog.jrtashjian.com/2008/09/16/planning-a-web-application/#comments</comments>
		<pubDate>Tue, 16 Sep 2008 16:15:54 +0000</pubDate>
		<dc:creator>jrtashjian</dc:creator>
		
		<category><![CDATA[Process]]></category>

		<guid isPermaLink="false">http://blog.jrtashjian.com/?p=14</guid>
		<description><![CDATA[We, as web developers, are always creating some sort of application that accomplishes the task at hand. A web application can be anything from a simple content management system to a full featured shopping cart. There are a lot of applications already created and free to use that accomplish those tasks. However, there is always [...]]]></description>
			<content:encoded><![CDATA[<p>We, as web developers, are always creating some sort of application that accomplishes the task at hand. A web application can be anything from a simple content management system to a full featured shopping cart. There are a lot of applications already created and free to use that accomplish those tasks. However, there is <em>always</em> a need for a custom implementation.</p>
<p>I do a lot of client work everyday, and a pre-developed solution is never enough. Every client and their needs are different and I am responsible to accommodate them. Sometimes I will use an existing solution but, I would need to modify the code to accomplish what the client asks for. When there is no existing solution the only thing we can do is develop the solution. Here are some pointers when creating a new application:</p>
<h3>Future Planning</h3>
<p>Planning for future releases/versions will alleviate a lot of pain when adding new features. Ask yourself what you may want to add at a later time and write it down. Be sure to keep your code clean and organized as well. Doing so will help reduce or even eliminate the need to rewrite a section of code.</p>
<h3>Create a project plan</h3>
<p>Planning for future releases/versions will alleviate a lot of pain when adding new features. Ask yourself what you may want to add at a later time and write it down. Be sure to keep your code clean and organized as well. Doing so will help reduce or even eliminate the need to rewrite a section of code.</p>
<h3>Build or Use an existing framework</h3>
<p>I personally enjoy creating my own library of tools and using them for every project I create. I know exactly what is going on in the script as well as how to fix any errors. However, a framework such as codeigniter has already taken care of that &#8220;dirty work&#8221; for you. If you use a third-party framework, be sure you read the documentation. The more you know and understand a framework, the easier it is to build application with it. Whichever works for you, use it and stick to it.</p>
<h3>Create a Coding Standard</h3>
<p>It is very important as a programmer that you adopt a way of coding that works for all. What I mean is, using the same format for comments, organizing code, visual formatting of code, etc&#8230; This will help you, as well as other coders, know what a section of code is for.</p>
<h3>Designing the Interface</h3>
<p>I am not much of a designer but, interface design is an interest of mine. Designing the interface for your application is very important. Take your time, your users are counting on you! Without a good interface, a user may not be able to use or understand your application or it&#8217;s purpose. Start by listing all of the actions that will be available and categorize them at your discretion. Figure out some sort of navigation for a user to easily accomplish those task. One easy way to keep you application simple and easy to use is to keep the interface simple.</p>
<h3>Begin Coding</h3>
<p>Once you are ready to begin developing the application, you need to start coding! Don&#8217;t get too caught up in planning your app or you will never start. An idea is only an idea unless you do something with it. Start small and as development progresses you can tackle the more advanced features.</p>
<p>Creating a web application is no easy task, depending on the type of project. If you have never created a web application I suggest you do so! Start with a simple news management system. Building a simple application will help you learn more about web development as well as add to your experience. It doesn&#8217;t matter if it&#8217;s already been done before. Experience is <em>very</em> valuable in this industry, and portraying that you know your stuff is equally important.</p>
<p>In closing, What kind of web applications have you created? Did they help you learn more to become a better developer? What do you do when planning a new application?</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jrtashjian.com/2008/09/16/planning-a-web-application/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Code Snippet: Recursive Delete with FTP</title>
		<link>http://blog.jrtashjian.com/2008/08/27/code-snippet-recursive-delete-with-ftp-2/</link>
		<comments>http://blog.jrtashjian.com/2008/08/27/code-snippet-recursive-delete-with-ftp-2/#comments</comments>
		<pubDate>Thu, 28 Aug 2008 03:02:02 +0000</pubDate>
		<dc:creator>jrtashjian</dc:creator>
		
		<category><![CDATA[Code Snippets]]></category>

		<guid isPermaLink="false">http://blog.jrtashjian.com/?p=12</guid>
		<description><![CDATA[I was recently creating an administration application for a client. The app involved working with files and directories as well as uploading and deleting files or directories. While I was developing, I ran into an issue that required a special function: recursive delete.
A recursive function is a function that has the ability to call itself [...]]]></description>
			<content:encoded><![CDATA[<p>I was recently creating an administration application for a client. The app involved working with files and directories as well as uploading and deleting files or directories. While I was developing, I ran into an issue that required a special function: recursive delete.</p>
<p>A recursive function is a function that has the ability to call itself (recursion). I ran into this problem while trying to delete a directory containing files and/or other directories. I was using FTP at the time so, the function will be written as such. It can be easily ported to using filesystem functions by following the same logic/flow.</p>
<p>Anyway, the use of <a title="PHP Manual - ftp_rmdir()" href="http://php.net/ftp_rmdir">ftp_rmdir()</a> was not enough. Using it to delete a directory containing files or folders only throws an error stating that the folder you are trying to delete contains other files. It was a little disappointing to see that PHP does not have a recursive delete function built in. So, I decided to write my own function. It works very well, it is small and it runs fast!</p>
<p>Well, here is the code:</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># server credentials</span>
<span style="color: #000088;">$host</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;ftp server&quot;</span>;
<span style="color: #000088;">$user</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;username&quot;</span>;
<span style="color: #000088;">$pass</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;password&quot;</span>;
&nbsp;
<span style="color: #666666; font-style: italic;"># connect to ftp server</span>
<span style="color: #000088;">$handle</span> <span style="color: #339933;">=</span> <span style="color: #339933;">@</span><span style="color: #990000;">ftp_connect</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$host</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Could not connect to {$host}&quot;</span><span style="color: #009900;">&#41;</span>;
&nbsp;
<span style="color: #666666; font-style: italic;"># login using credentials</span>
<span style="color: #339933;">@</span><span style="color: #990000;">ftp_login</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$handle</span><span style="color: #339933;">,</span> <span style="color: #000088;">$user</span><span style="color: #339933;">,</span> <span style="color: #000088;">$pass</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Could not login to {$host}&quot;</span><span style="color: #009900;">&#41;</span>;
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> recursiveDelete<span style="color: #009900;">&#40;</span><span style="color: #000088;">$directory</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;"># here we attempt to delete the file/directory</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">@</span><span style="color: #990000;">ftp_rmdir</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$handle</span><span style="color: #339933;">,</span> <span style="color: #000088;">$directory</span><span style="color: #009900;">&#41;</span> || <span style="color: #339933;">@</span><span style="color: #990000;">ftp_delete</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$handle</span><span style="color: #339933;">,</span> <span style="color: #000088;">$directory</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;"># if the attempt to delete fails, get the file listing</span>
		<span style="color: #000088;">$filelist</span> <span style="color: #339933;">=</span> <span style="color: #339933;">@</span><span style="color: #990000;">ftp_nlist</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$handle</span><span style="color: #339933;">,</span> <span style="color: #000088;">$directory</span><span style="color: #009900;">&#41;</span>;
&nbsp;
		<span style="color: #666666; font-style: italic;"># loop through the file list and recursively delete the FILE in the list</span>
		<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$filelist</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$file</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			recursiveDelete<span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #009900;">&#41;</span>;
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">#if the file list is empty, delete the DIRECTORY we passed</span>
		recursiveDelete<span style="color: #009900;">&#40;</span><span style="color: #000088;">$directory</span><span style="color: #009900;">&#41;</span>;
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The comments explain what is going on but, I will explain a little more right now. Basically, you pass the directory you want to delete to the function. The function will try to delete the file/directory that was passed to it. If the function fails to delete the directory/file, it will attempt to enter the directory and get a file list. The function then loops through the file list and calls itself by passing the file or directory from the list. It will repeat this until there are no more files or directories inside the directory you passed for removal. Once that is complete, it will re-attempt to delete the directory you passed to it.</p>
<p>Thats it! Very small script, yet very powerful. Be careful when creating these kinds of functions as you don&#8217;t want the function to accidentally delete more than you intended. Just a quick note about the function, <strong>make sure you include a trailing slash at the end of the directory!</strong> If you forget to, this function will try and delete the files and directories where the directory you passed is contained. It&#8217;s a good habit to get into anyway. I was flooding the FTP server at work with requests to delete directories I didn&#8217;t want to delete because I forgot to add the trailing slash! Good thing the file permissions stopped it!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jrtashjian.com/2008/08/27/code-snippet-recursive-delete-with-ftp-2/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Site Launched!</title>
		<link>http://blog.jrtashjian.com/2008/08/27/site-launched/</link>
		<comments>http://blog.jrtashjian.com/2008/08/27/site-launched/#comments</comments>
		<pubDate>Thu, 28 Aug 2008 00:10:30 +0000</pubDate>
		<dc:creator>jrtashjian</dc:creator>
		
		<category><![CDATA[News]]></category>

		<guid isPermaLink="false">http://blog.jrtashjian.com/?p=10</guid>
		<description><![CDATA[Hey everyone! My name is JR Tashjian and I am a Web Developer living and working in New York.
I started this blog because I wanted to write about what I do and what I learn as well as educate any readers wanting to learn more about Web Development. I will be focusing on the Back-End [...]]]></description>
			<content:encoded><![CDATA[<p>Hey everyone! My name is JR Tashjian and I am a Web Developer living and working in New York.</p>
<p>I started this blog because I wanted to write about what I do and what I learn as well as educate any readers wanting to learn more about Web Development. I will be focusing on the Back-End (server side) coding of projects using PHP and MySQL. I will also write a little about Front-End (client side) coding using HTML, CSS and JavaScript. As for post consistency, I haven&#8217;t set anything nor do I plan to. I will write articles as I have time but, I will aim for one or two posts a week.</p>
<p>Well, I am very excited about this launch! I hope everyone who reads my articles will find this site a valuable resource for learning Web Development. If you have any topics you would like me to write about or have a question you want answered, feel free to email me using the form on the contact page. You can also reach me a jrtashjian[at]gmail[dot]com and I will get back to you as soon as I can.</p>
<p>Check back often for updates! While your waiting, get the <a href="http://blog.jrtashjian.com/feed/">feed</a>!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jrtashjian.com/2008/08/27/site-launched/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
