<?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>Alex M's Blog &#187; implode</title>
	<atom:link href="http://blog.alexmckenzie.info/tag/implode/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.alexmckenzie.info</link>
	<description>Somewhat useful things</description>
	<lastBuildDate>Tue, 19 Jul 2011 12:01:31 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Uppercase first word in a string or sentence</title>
		<link>http://blog.alexmckenzie.info/2009/05/24/uppercase-first-word-in-a-string-or-sentence/</link>
		<comments>http://blog.alexmckenzie.info/2009/05/24/uppercase-first-word-in-a-string-or-sentence/#comments</comments>
		<pubDate>Sun, 24 May 2009 11:36:30 +0000</pubDate>
		<dc:creator>Alex M</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[explode]]></category>
		<category><![CDATA[implode]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[strtolower]]></category>
		<category><![CDATA[ucfirst]]></category>

		<guid isPermaLink="false">http://blog.alexmckenzie.info/?p=28</guid>
		<description><![CDATA[I have just had a task which requires making the first word of a string uppercase. I have come up with quite an easy and simple solution and thought I would share it with you. An example input string might &#8230; <a href="http://blog.alexmckenzie.info/2009/05/24/uppercase-first-word-in-a-string-or-sentence/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I have just had a task which requires making the first word of a string uppercase. I have come up with quite an easy and simple solution and thought I would share it with you.</p>
<p>An example input string might look like &#8220;HELLO world. This is a test.&#8221; The required output is &#8220;Hello world. This is a test.&#8221;</p>
<p>Below is a function which will help you achieve this:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> uc_first_word<span style="color: #009900;">&#40;</span><span style="color: #000088;">$string</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$s</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;">$string</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$s</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</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;">$s</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: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$s</span> <span style="color: #339933;">=</span> <span style="color: #990000;">implode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">' '</span><span style="color: #339933;">,</span> <span style="color: #000088;">$s</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #000088;">$s</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Now I know this function isn&#8217;t full proof, and assumes that the string you are passing actually contains words. If the first word was a roman numeral for example, this function would not work (ie VI would become Vi).</p>
<p>Usage of this function is quite easy:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$string</span> <span style="color: #339933;">=</span> uc_first_word<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'HELLO world. This is a test.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>I hope that this might help someone searching for a similar solution.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.alexmckenzie.info/2009/05/24/uppercase-first-word-in-a-string-or-sentence/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>

