<?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>Bright Cherry &#187; PHP Scripts, Tips &amp; Tricks</title>
	<atom:link href="http://www.brightcherry.co.uk/scribbles/category/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.brightcherry.co.uk/scribbles</link>
	<description></description>
	<lastBuildDate>Tue, 20 Dec 2011 19:54:41 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>PHP- Alternative To The Depreciated mime_content_type Function And Fileinfo Functions</title>
		<link>http://www.brightcherry.co.uk/scribbles/php-alternative-to-the-depreciated-mime_content_type-function-and-fileinfo-functions/</link>
		<comments>http://www.brightcherry.co.uk/scribbles/php-alternative-to-the-depreciated-mime_content_type-function-and-fileinfo-functions/#comments</comments>
		<pubDate>Tue, 20 Dec 2011 19:54:26 +0000</pubDate>
		<dc:creator>adm1n</dc:creator>
				<category><![CDATA[PHP Scripts, Tips & Tricks]]></category>

		<guid isPermaLink="false">http://www.brightcherry.co.uk/scribbles/?p=453</guid>
		<description><![CDATA[You&#8217;ve probably landed on this page because you want to find the Content-type of a file by using the mime_content_type function. But when you tried using the function, you were returned with a PHP error because it&#8217;s a depreciated function (PHP 4). Then you may have tried to use the Fileinfo function (am alternative suggested [...]]]></description>
			<content:encoded><![CDATA[<p>You&#8217;ve probably landed on this page because you want to find the <b class="pink">Content-type</b> of a file by using the <a href="http://php.net/manual/en/function.mime-content-type.php" target="new" rel="nofollow" title"PHP mime_content_type">mime_content_type function</a>. But when you tried using the function, you were returned with a PHP error because it&#8217;s a depreciated function (PHP 4). Then you may have tried to use the <a href="http://www.php.net/manual/en/ref.fileinfo.php" target="new" rel="nofollow" title"PHP Fileinfo function">Fileinfo function</a> (am alternative suggested by the PHP website), but then realised you haven&#8217;t got the PHP Fileinfo extension/library installed (because you were returned with an error again). <b>So what&#8217;s your alternative</b>?</p>
<h4>Possible solutions</h4>
<ul>
<li>Firstly, if you&#8217;re running off a dedicated sever or VPS, you could install the Fileinfo extension. However, if you&#8217;re on hosted on a shared server, your hosting provider may not install the extension for you. But it might be worth trying to contact them to get it installed first.</li>
<li>The second solution is to write your own function, which is the code I&#8217;m going to provide in this blog post</li>
</ul>
<h4>Write your own mime_content_type Function</h4>

<div class="wp_codebox"><table><tr id="p4532"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
</pre></td><td class="code" id="p453code2"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">function_exists</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'mime_content_type'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">function</span> <span style="color: #990000;">mime_content_type</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$filename</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$idx</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;">$filename</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$count_explode</span> <span style="color: #339933;">=</span> <span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$idx</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$idx</span> <span style="color: #339933;">=</span> <span style="color: #990000;">strtolower</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$idx</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$count_explode</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$mimet</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>	
        <span style="color: #0000ff;">'ai'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'application/postscript'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'aif'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'audio/x-aiff'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'aifc'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'audio/x-aiff'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'aiff'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'audio/x-aiff'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'asc'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'text/plain'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'atom'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'application/atom+xml'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'avi'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'video/x-msvideo'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'bcpio'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'application/x-bcpio'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'bmp'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'image/bmp'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'cdf'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'application/x-netcdf'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'cgm'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'image/cgm'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'cpio'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'application/x-cpio'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'cpt'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'application/mac-compactpro'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'crl'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'application/x-pkcs7-crl'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'crt'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'application/x-x509-ca-cert'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'csh'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'application/x-csh'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'css'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'text/css'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'dcr'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'application/x-director'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'dir'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'application/x-director'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'djv'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'image/vnd.djvu'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'djvu'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'image/vnd.djvu'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'doc'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'application/msword'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'dtd'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'application/xml-dtd'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'dvi'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'application/x-dvi'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'dxr'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'application/x-director'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'eps'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'application/postscript'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'etx'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'text/x-setext'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'ez'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'application/andrew-inset'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'gif'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'image/gif'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'gram'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'application/srgs'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'grxml'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'application/srgs+xml'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'gtar'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'application/x-gtar'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'hdf'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'application/x-hdf'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'hqx'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'application/mac-binhex40'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'html'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'text/html'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'html'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'text/html'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'ice'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'x-conference/x-cooltalk'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'ico'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'image/x-icon'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'ics'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'text/calendar'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'ief'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'image/ief'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'ifb'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'text/calendar'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'iges'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'model/iges'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'igs'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'model/iges'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'jpe'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'image/jpeg'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'jpeg'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'image/jpeg'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'jpg'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'image/jpeg'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'js'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'application/x-javascript'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'kar'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'audio/midi'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'latex'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'application/x-latex'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'m3u'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'audio/x-mpegurl'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'man'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'application/x-troff-man'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'mathml'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'application/mathml+xml'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'me'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'application/x-troff-me'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'mesh'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'model/mesh'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'mid'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'audio/midi'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'midi'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'audio/midi'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'mif'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'application/vnd.mif'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'mov'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'video/quicktime'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'movie'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'video/x-sgi-movie'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'mp2'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'audio/mpeg'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'mp3'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'audio/mpeg'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'mpe'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'video/mpeg'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'mpeg'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'video/mpeg'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'mpg'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'video/mpeg'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'mpga'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'audio/mpeg'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'ms'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'application/x-troff-ms'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'msh'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'model/mesh'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'mxu m4u'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'video/vnd.mpegurl'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'nc'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'application/x-netcdf'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'oda'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'application/oda'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'ogg'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'application/ogg'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'pbm'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'image/x-portable-bitmap'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'pdb'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'chemical/x-pdb'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'pdf'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'application/pdf'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'pgm'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'image/x-portable-graymap'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'pgn'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'application/x-chess-pgn'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'php'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'application/x-httpd-php'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'php4'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'application/x-httpd-php'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'php3'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'application/x-httpd-php'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'phtml'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'application/x-httpd-php'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'phps'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'application/x-httpd-php-source'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'png'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'image/png'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'pnm'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'image/x-portable-anymap'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'ppm'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'image/x-portable-pixmap'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'ppt'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'application/vnd.ms-powerpoint'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'ps'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'application/postscript'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'qt'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'video/quicktime'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'ra'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'audio/x-pn-realaudio'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'ram'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'audio/x-pn-realaudio'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'ras'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'image/x-cmu-raster'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'rdf'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'application/rdf+xml'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'rgb'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'image/x-rgb'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'rm'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'application/vnd.rn-realmedia'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'roff'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'application/x-troff'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'rtf'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'text/rtf'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'rtx'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'text/richtext'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'sgm'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'text/sgml'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'sgml'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'text/sgml'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'sh'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'application/x-sh'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'shar'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'application/x-shar'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'shtml'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'text/html'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'silo'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'model/mesh'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'sit'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'application/x-stuffit'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'skd'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'application/x-koan'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'skm'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'application/x-koan'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'skp'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'application/x-koan'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'skt'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'application/x-koan'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'smi'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'application/smil'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'smil'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'application/smil'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'snd'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'audio/basic'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'spl'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'application/x-futuresplash'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'src'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'application/x-wais-source'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'sv4cpio'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'application/x-sv4cpio'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'sv4crc'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'application/x-sv4crc'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'svg'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'image/svg+xml'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'swf'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'application/x-shockwave-flash'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'t'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'application/x-troff'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'tar'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'application/x-tar'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'tcl'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'application/x-tcl'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'tex'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'application/x-tex'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'texi'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'application/x-texinfo'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'texinfo'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'application/x-texinfo'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'tgz'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'application/x-tar'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'tif'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'image/tiff'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'tiff'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'image/tiff'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'tr'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'application/x-troff'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'tsv'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'text/tab-separated-values'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'txt'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'text/plain'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'ustar'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'application/x-ustar'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'vcd'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'application/x-cdlink'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'vrml'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'model/vrml'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'vxml'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'application/voicexml+xml'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'wav'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'audio/x-wav'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'wbmp'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'image/vnd.wap.wbmp'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'wbxml'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'application/vnd.wap.wbxml'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'wml'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'text/vnd.wap.wml'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'wmlc'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'application/vnd.wap.wmlc'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'wmlc'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'application/vnd.wap.wmlc'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'wmls'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'text/vnd.wap.wmlscript'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'wmlsc'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'application/vnd.wap.wmlscriptc'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'wmlsc'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'application/vnd.wap.wmlscriptc'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'wrl'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'model/vrml'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'xbm'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'image/x-xbitmap'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'xht'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'application/xhtml+xml'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'xhtml'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'application/xhtml+xml'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'xls'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'application/vnd.ms-excel'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'xml xsl'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'application/xml'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'xpm'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'image/x-xpixmap'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'xslt'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'application/xslt+xml'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'xul'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'application/vnd.mozilla.xul+xml'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'xwd'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'image/x-xwindowdump'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'xyz'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'chemical/x-xyz'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'zip'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'application/zip'</span>
	<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$mimet</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$idx</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	 <span style="color: #b1b100;">return</span> <span style="color: #000088;">$mimet</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$idx</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
	 <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">'application/octet-stream'</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//$mm_type will return the content type (note, I still use the original function name mime_content_type)</span>
<span style="color: #000088;">$mm_type</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mime_content_type</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$filepath</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>If anyone has a better solution of retrieving the content-type without using the depreciated mime_content_type function and the Fileinfo library, please let me know.</p>
<p>Also, please let me know if this worked for you <img src='http://www.brightcherry.co.uk/scribbles/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.brightcherry.co.uk/scribbles/php-alternative-to-the-depreciated-mime_content_type-function-and-fileinfo-functions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP- List All Directories/Folders From A Specified Location</title>
		<link>http://www.brightcherry.co.uk/scribbles/php-list-all-directoriesfolders-from-a-specified-location/</link>
		<comments>http://www.brightcherry.co.uk/scribbles/php-list-all-directoriesfolders-from-a-specified-location/#comments</comments>
		<pubDate>Wed, 20 Jul 2011 01:07:11 +0000</pubDate>
		<dc:creator>adm1n</dc:creator>
				<category><![CDATA[PHP Scripts, Tips & Tricks]]></category>

		<guid isPermaLink="false">http://www.brightcherry.co.uk/scribbles/?p=393</guid>
		<description><![CDATA[This is a quick extension/counterpart to my existing blog post that explains how to List All Files In A Directory in PHP. But instead of listing all files, I&#8217;m quickly going to jot down how to list all directories/folders in a specified location. Someone had asked in the comments section how to do it, so [...]]]></description>
			<content:encoded><![CDATA[<p>This is a quick extension/counterpart to my existing blog post that explains how to <a href="http://www.brightcherry.co.uk/scribbles/2008/11/02/php-list-all-files-in-a-directory/" title="List All Files In A Directory in PHP">List All Files In A Directory in PHP</a>. But instead of listing all files, I&#8217;m quickly going to jot down how to list all directories/folders in a specified location. </p>
<p>Someone had asked in the comments section how to do it, so I thought I&#8217;d quickly write a blog post about it. It&#8217;s actually not much different from the code I used to list all files in a directory- all that&#8217;s required is an extra function, <b class="pink">is_dir</b>. The PHP code is very simple and only requires a small amount of code. I’ve seen a lot of examples on other forums/websites that use a ridiculous amount of code to get the same result, and i’m not quite sure why.</p>
<h4>Here&#8217;s how to list all files in a directory</h4>

<div class="wp_codebox"><table><tr id="p3934"><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" id="p393code4"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//path to directory to scan</span>
<span style="color: #000088;">$directory</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;index_files/&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//get all files in specified directory</span>
<span style="color: #000088;">$files</span> <span style="color: #339933;">=</span> <span style="color: #990000;">glob</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$directory</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;*&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//print each file name</span>
<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$files</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>
 <span style="color: #666666; font-style: italic;">//check to see if the file is a folder/directory</span>
 <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">is_dir</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
 <span style="color: #009900;">&#123;</span>
  <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$file</span><span style="color: #339933;">;</span>
 <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>I hope this helps someone out.</p>
<p>As always, if anyone knows of a more efficient way of doing this, please let me know.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.brightcherry.co.uk/scribbles/php-list-all-directoriesfolders-from-a-specified-location/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PHP &#8211; Changing Date Format</title>
		<link>http://www.brightcherry.co.uk/scribbles/php-changing-date-format/</link>
		<comments>http://www.brightcherry.co.uk/scribbles/php-changing-date-format/#comments</comments>
		<pubDate>Tue, 08 Mar 2011 23:53:35 +0000</pubDate>
		<dc:creator>adm1n</dc:creator>
				<category><![CDATA[PHP Scripts, Tips & Tricks]]></category>

		<guid isPermaLink="false">http://www.brightcherry.co.uk/scribbles/?p=318</guid>
		<description><![CDATA[A friend of mine has been struggling to format a date string he&#8217;s pulling out from a MySQL table. He&#8217;s just started learning PHP, so he&#8217;s still getting to grips with things. When he came to me with his problem, I sent him a link to the date function, but he couldn&#8217;t understand the manual&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>A friend of mine has been struggling to format a date string he&#8217;s pulling out from a MySQL table. He&#8217;s just started learning PHP, so he&#8217;s still getting to grips with things.</p>
<p>When he came to me with his problem, I sent him a link to the <a href="http://php.net/manual/en/function.date.php" title="PHP Date Function" target="new" rel="nofollow">date function</a>, but he couldn&#8217;t understand the manual&#8217;s example. I can actually relate, because when I first started learning PHP, the manual didn&#8217;t make much sense to me.</p>
<h4>The scenario</h4>
<p><strong>The date from the DB being pulled out is:</strong></p>

<div class="wp_codebox"><table><tr id="p3189"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p318code9"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$db_date</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;2011-12-31&quot;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// (yyyy-mm-dd)</span></pre></td></tr></table></div>

<p><strong>My friend wants it in the following format:</strong></p>

<div class="wp_codebox"><table><tr id="p31810"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p318code10"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$new_format_date</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;12-31-2011&quot;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// (dd-mm-yyyy)</span></pre></td></tr></table></div>

<h4>The solution</h4>

<div class="wp_codebox"><table><tr id="p31811"><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code" id="p318code11"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$db_date</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;2011-12-31&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$new_format_date</span> <span style="color: #339933;">=</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;d-m-Y&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$db_date</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$new_format_date</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>If $db_date is not a proper time format, you will be returned with 01-01-1970. That means you will need to parse the $db_date variable into a Unix timestamp by using the <b class="pink">strtotime</b> function.</p>

<div class="wp_codebox"><table><tr id="p31812"><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code" id="p318code12"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$db_date</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;2011-12-31&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$new_format_date</span> <span style="color: #339933;">=</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;d-m-Y&quot;</span><span style="color: #339933;">,</span> <span style="color: #990000;">strtotime</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$db_date</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$new_format_date</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>It&#8217;s as easy as that.<br />
I hope that helps out someone else.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.brightcherry.co.uk/scribbles/php-changing-date-format/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PHP &#8211; Creating A Year (date) Loop</title>
		<link>http://www.brightcherry.co.uk/scribbles/php-creating-a-year-date-loop/</link>
		<comments>http://www.brightcherry.co.uk/scribbles/php-creating-a-year-date-loop/#comments</comments>
		<pubDate>Thu, 30 Sep 2010 08:22:29 +0000</pubDate>
		<dc:creator>adm1n</dc:creator>
				<category><![CDATA[PHP Scripts, Tips & Tricks]]></category>

		<guid isPermaLink="false">http://www.brightcherry.co.uk/scribbles/?p=250</guid>
		<description><![CDATA[Here&#8217;s a good/efficient way of building a loop of years from a starting point to an ending point. For example, this code will show you how to print a range of years from 2000 to 2010: 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 The code is particularly useful if you want to [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a good/efficient way of building a loop of years from a starting point to an ending point. For example, this code will show you how to print a range of years from 2000 to 2010:</p>
<p>2001<br />
2002<br />
2003<br />
2004<br />
2005<br />
2006<br />
2007<br />
2008<br />
2009<br />
2010</p>
<p>The code is particularly useful if you want to create a dropdown for years. The example will output a list of years ranging from 1960 to the current year.</p>

<div class="wp_codebox"><table><tr id="p25015"><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" id="p250code15"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?</span>
<span style="color: #666666; font-style: italic;">//year to start with</span>
<span style="color: #000088;">$startdate</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1960</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//year to end with - this is set to current year. You can change to specific year</span>
<span style="color: #000088;">$enddate</span> <span style="color: #339933;">=</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Y&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$years</span> <span style="color: #339933;">=</span> <span style="color: #990000;">range</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$startdate</span><span style="color: #339933;">,</span><span style="color: #000088;">$enddate</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//print years</span>
<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$years</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$year</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$year</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;&lt;br /&gt;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<h4>Update: Solution 2</h4>
<p>I&#8217;ve just been messing around with some code, and I&#8217;ve figured out an alternative way of doing it, but with less code!</p>
<p>This code works kind of differently, but returns the same output (kind of). Unlike the previous solution, you don&#8217;t specify the start date, instead you specify how many years you want to go back from the current year. However, because you specify how many years you want to show, each time we&#8217;re into a new year, the oldest year will increase by 1 year. So if you go back 50 years, the date range will be 1960 &#8211; 2010. But next year (2011), the date range will be 1961 &#8211; 2011.</p>

<div class="wp_codebox"><table><tr id="p25016"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code" id="p250code16"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//The 60 value here is the amount of years to go back</span>
<span style="color: #000088;">$year</span> <span style="color: #339933;">=</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Y&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> <span style="color: #cc66cc;">50</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//The 60 value here is the amount of years to go forward</span>
<span style="color: #666666; font-style: italic;">//because i went back 50 years, i'm going forward 50 years so the dropdown will always have the current year.</span>
<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span> <span style="color: #339933;">&lt;=</span> <span style="color: #cc66cc;">50</span><span style="color: #339933;">;</span> <span style="color: #339933;">++</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$year</span><span style="color: #339933;">;</span> 
  <span style="color: #666666; font-style: italic;">//increase year counter by 1    </span>
  <span style="color: #339933;">++</span><span style="color: #000088;">$year</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Please let me know if you know of a better way to achieve the same output.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.brightcherry.co.uk/scribbles/php-creating-a-year-date-loop/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>PHP &#8211; Capitalize First Letter Of Every Sentence For Proper Formatting</title>
		<link>http://www.brightcherry.co.uk/scribbles/php-capitalize-first-letter-of-every-sentence/</link>
		<comments>http://www.brightcherry.co.uk/scribbles/php-capitalize-first-letter-of-every-sentence/#comments</comments>
		<pubDate>Sat, 31 Jul 2010 08:45:54 +0000</pubDate>
		<dc:creator>adm1n</dc:creator>
				<category><![CDATA[PHP Scripts, Tips & Tricks]]></category>

		<guid isPermaLink="false">http://www.brightcherry.co.uk/scribbles/?p=233</guid>
		<description><![CDATA[Here&#8217;s an extremely useful snippet of code that will properly format sentences with capitalization. Actually, what the code really does is capitialize every letter AFTER a full-stop (period). Here&#8217;s an example of what the code will do&#8230; Before: Hello This Is An Example Of A Sentence Which Has Odd Capitalization Which You May Want Fixing. [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s an extremely useful snippet of code that will properly format sentences with capitalization. Actually, what the code really does is capitialize every letter AFTER a full-stop (period). Here&#8217;s an example of what the code will do&#8230;</p>
<h4>Before:</h4>
<blockquote><p>
Hello This Is An Example Of A Sentence Which Has Odd Capitalization Which You May Want Fixing. tHere Are Problems With This Method, Which I Will disclose Shortly. If You Know How To Improve THis Code Please Let Me Know.
</p></blockquote>
<h4>After:</h4>
<blockquote><p>
Hello this is an example of a sentence which has odd capitalization which you may want fixing. There are problems with this method, which i will disclose shortly. If you know how to improve this code please let me know.
</p></blockquote>

<div class="wp_codebox"><table><tr id="p23319"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code" id="p233code19"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//define string</span>
<span style="color: #000088;">$string</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Hello This Is An Example Of A Sentence Which Has Odd Capitalization Which You May Want Fixing. tHere Are Problems With This Method, Which I Will disclose Shortly. If You Know How To Improve THis Code Please Let Me Know.&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//first we make everything lowercase, and then make the first letter if the entire string capitalized</span>
<span style="color: #000088;">$string</span> <span style="color: #339933;">=</span> <span style="color: #990000;">ucfirst</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">strtolower</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$string</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//now we run the function to capitalize every letter AFTER a full-stop (period).</span>
<span style="color: #000088;">$string</span> <span style="color: #339933;">=</span> <span style="color: #990000;">preg_replace_callback</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/[.!?].*?\w/'</span><span style="color: #339933;">,</span> <span style="color: #990000;">create_function</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'$matches'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'return strtoupper($matches[0]);'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #000088;">$string</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//print the result</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$string</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>There you have it. But there are flaws with this code, which you should be aware of.</p>
<h4>Recognised problems to consider</h4>
<p>This code will only capitalize the first letter of the string and all letters after full-stops (periods). Names, acronyms and countries will become lowercase when they should be capitalized.</p>
<p>Acronyms with full-stops won&#8217;t return as they should appear. For example, &#8220;e.g.&#8221; will return as &#8220;e.G.&#8221; because the G is directly after a full-stop.</p>
<p>A common problem is the word &#8220;I&#8221;, it will be returned in lowercase. For example, &#8220;You and i may have to make some exceptions&#8221;</p>
<h5>Solutions</h5>
<p>The way I overcome these issues by making rules with the str_replace function. Put these exceptions after the function has run and before printing the results. This isn&#8217;t an ideal solution for large lumps of data as there would be a lot of exceptions, but it&#8217;s useful for a manageable data size. You could, however, create your own function(s) to make the clean up process quicker and easier to handle large data.</p>
<h4>Possible solutions</h4>

<div class="wp_codebox"><table><tr id="p23320"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code" id="p233code20"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #666666; font-style: italic;">//to overcome the e.G. problem</span>
<span style="color: #000088;">$string</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;e.G.&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;e.g.&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$string</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//to overcome the lowercase i problem</span>
<span style="color: #000088;">$string</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot; i &quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot; I &quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$string</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//to overcome the acronym problem</span>
<span style="color: #000088;">$string</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;dps&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;DPS&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$string</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Does anyone have any better solutions, or perhaps even improvements to the existing code?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.brightcherry.co.uk/scribbles/php-capitalize-first-letter-of-every-sentence/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

