<?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>DOC776.org &#187; useful</title>
	<atom:link href="http://www.doc776.org/tag/useful/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.doc776.org</link>
	<description>This is the era of information.</description>
	<lastBuildDate>Mon, 02 Jan 2012 00:05:25 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Get File Extension</title>
		<link>http://www.doc776.org/2009/06/get-file-extension/</link>
		<comments>http://www.doc776.org/2009/06/get-file-extension/#comments</comments>
		<pubDate>Tue, 30 Jun 2009 07:09:02 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[useful]]></category>

		<guid isPermaLink="false">http://www.doc776.org/?p=152</guid>
		<description><![CDATA[Very handy PHP function to get the file extension of a file name like something.jpg Method 1: (best way) 1 2 3 4 5 6 7 8 9 10 11 // get_file_extension ( string [the file name] , boolean [lower case] ) function get_file_extension&#40;$str,$low = true&#41;&#123; $i = strrpos&#40;$str,'.'&#41;; if &#40;!$i&#41; return ''; $l = [...]]]></description>
			<content:encoded><![CDATA[<p>Very handy PHP function to get the file extension of a file name like something.jpg</p>
<p><strong>Method 1:  (best way)</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// get_file_extension ( string [the file name] , boolean [lower case] )</span>
<span style="color: #000000; font-weight: bold;">function</span> get_file_extension<span style="color: #009900;">&#40;</span><span style="color: #000088;">$str</span><span style="color: #339933;">,</span><span style="color: #000088;">$low</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #990000;">strrpos</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$str</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#41;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$l</span> <span style="color: #339933;">=</span> <span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$str</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$i</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$ext</span> <span style="color: #339933;">=</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$str</span><span style="color: #339933;">,</span><span style="color: #000088;">$i</span><span style="color: #339933;">+</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span><span style="color: #000088;">$l</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$low</span> <span style="color: #339933;">==</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span>
	<span style="color: #000088;">$ext</span> <span style="color: #339933;">=</span> <span style="color: #990000;">strtolower</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ext</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$ext</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p><strong>Method 2:</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// get_file_extension ( string [the file name] , boolean [lower case] )</span>
<span style="color: #000000; font-weight: bold;">function</span> get_file_extension<span style="color: #009900;">&#40;</span><span style="color: #000088;">$str</span><span style="color: #339933;">,</span><span style="color: #000088;">$low</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$ar</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'.'</span><span style="color: #339933;">,</span><span style="color: #000088;">$str</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ar</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$ar</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array_reverse</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ar</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$low</span> <span style="color: #339933;">==</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span>
	<span style="color: #000088;">$ext</span> <span style="color: #339933;">=</span> <span style="color: #990000;">strtolower</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ar</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$ext</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Both functions produce the same output but one uses the string functions and the other uses array function. If you think about it, to manipulate and create arrays take more memory then manipulating regular text. (internally arrays are created using those same string manipulation methods) So method one is better because it uses most simple way to get what you need.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.doc776.org/2009/06/get-file-extension/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Make Code</title>
		<link>http://www.doc776.org/2009/06/make-code/</link>
		<comments>http://www.doc776.org/2009/06/make-code/#comments</comments>
		<pubDate>Tue, 30 Jun 2009 07:03:03 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[useful]]></category>

		<guid isPermaLink="false">http://www.doc776.org/?p=149</guid>
		<description><![CDATA[Very simple handy little function to generate a random code of number and lower and upper case letters. Straight forward stuff&#8230; 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 function makecode($chars = 6) { for($i=0; $i&#60;=($chars-1); $i++) { $r0 = rand(0,1); $r1 = rand(0,2); // frequency of lower [...]]]></description>
			<content:encoded><![CDATA[<p>Very simple handy little function to generate a random code of number and lower and upper case letters.</p>
<p>Straight forward stuff&#8230;</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
</pre></td><td class="code"><pre class="language" style="font-family:monospace;">function makecode($chars = 6)
{
	for($i=0; $i&lt;=($chars-1); $i++)
	{
		$r0 = rand(0,1);
		$r1 = rand(0,2); // frequency of lower case
		if($r0==0)
			$r .= chr(rand(ord('A'),ord('Z')));
		elseif($r0==1)
			$r .= rand(0,9);
		if($r1==0)
			$r = strtolower($r);
	}
	return $r;
}</pre></td></tr></table></div>

<p>$r0 controls if the next digit is a number or a letter<br />
$1 controls if teh letter will be upper or lower. Set it to 0 if you want it to always be lower or change the range to what ever suits you.<br />
Also a number maybe passed to the function to change how many digits in the code to make.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.doc776.org/2009/06/make-code/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

