<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: Title Case in PHP</title>
	<atom:link href="http://www.sitepoint.com/blogs/2005/03/15/title-case-in-php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.sitepoint.com/blogs/2005/03/15/title-case-in-php/</link>
	<description>News, opinion, and fresh thinking for web developers and designers. The official podcast of sitepoint.com.</description>
	<lastBuildDate>Sat, 07 Nov 2009 23:35:20 -0500</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: amber.long83</title>
		<link>http://www.sitepoint.com/blogs/2005/03/15/title-case-in-php/comment-page-1/#comment-848053</link>
		<dc:creator>amber.long83</dc:creator>
		<pubDate>Sat, 13 Dec 2008 09:34:53 +0000</pubDate>
		<guid isPermaLink="false">1274596269#comment-848053</guid>
		<description>nice function. thanks</description>
		<content:encoded><![CDATA[<p>nice function. thanks</p>]]></content:encoded>
	</item>
	<item>
		<title>By: JimS</title>
		<link>http://www.sitepoint.com/blogs/2005/03/15/title-case-in-php/comment-page-1/#comment-571831</link>
		<dc:creator>JimS</dc:creator>
		<pubDate>Wed, 26 Dec 2007 21:29:42 +0000</pubDate>
		<guid isPermaLink="false">1274596269#comment-571831</guid>
		<description>My god... what a bunch of whiners (for the most part). And a lot of non-programmers who want to complain about improper grammar. It&#039;s a tool. Use it. Don&#039;t use it. Modify as needed. 

And ddzoom...
If you modify ALLCAP titles then the previous example where &quot;A Title About HTML Classes&quot; would obviously damage HTML if it was inputed properly the first time around.

Jim</description>
		<content:encoded><![CDATA[<p>My god&#8230; what a bunch of whiners (for the most part). And a lot of non-programmers who want to complain about improper grammar. It&#8217;s a tool. Use it. Don&#8217;t use it. Modify as needed. </p>
<p>And ddzoom&#8230;<br />
If you modify ALLCAP titles then the previous example where &#8220;A Title About HTML Classes&#8221; would obviously damage HTML if it was inputed properly the first time around.</p>
<p>Jim</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Edan</title>
		<link>http://www.sitepoint.com/blogs/2005/03/15/title-case-in-php/comment-page-1/#comment-442742</link>
		<dc:creator>Edan</dc:creator>
		<pubDate>Thu, 08 Nov 2007 11:08:32 +0000</pubDate>
		<guid isPermaLink="false">1274596269#comment-442742</guid>
		<description>Thanks for the code.
Even if it doesn&#039;t provide me a complete grammar resource -
I found it very useful.

Anyway, for the last word problem, I added this line -

$words[array_pop(array_keys($words))] = ucwords($word);</description>
		<content:encoded><![CDATA[<p>Thanks for the code.<br />
Even if it doesn&#8217;t provide me a complete grammar resource -<br />
I found it very useful.</p>
<p>Anyway, for the last word problem, I added this line -</p>
<p>$words[array_pop(array_keys($words))] = ucwords($word);</p>]]></content:encoded>
	</item>
	<item>
		<title>By: ddzoom</title>
		<link>http://www.sitepoint.com/blogs/2005/03/15/title-case-in-php/comment-page-1/#comment-227963</link>
		<dc:creator>ddzoom</dc:creator>
		<pubDate>Wed, 18 Apr 2007 17:01:23 +0000</pubDate>
		<guid isPermaLink="false">1274596269#comment-227963</guid>
		<description>&lt;pre&gt;&lt;code class=&quot;html&quot;&gt;function titlecase($s) {
 $GLOBALS[&#039;lc&#039;] = array(&#039;a&#039;, &#039;an&#039;, &#039;and&#039;, &#039;as&#039;, &#039;at&#039;, &#039;but&#039;, &#039;by&#039;, &#039;de&#039;, &#039;down&#039;, &#039;for&#039;, &#039;from&#039;, &#039;has&#039;, &#039;in&#039;, &#039;into&#039;, &#039;near&#039;, &#039;nor&#039;, &#039;of&#039;, &#039;off&#039;, &#039;onto&#039;, &#039;or&#039;, &#039;out&#039;, &#039;over&#039;, &#039;per&#039;, &#039;so&#039;, &#039;than&#039;, &#039;the&#039;, &#039;to&#039;, &#039;unto&#039;, &#039;upon&#039;, &#039;van&#039;, &#039;via&#039;, &#039;von&#039;, &#039;with&#039;, &#039;yet&#039;); // , &#039;up&#039;
 // $GLOBALS[&#039;lc&#039;] = array(&#039;a&#039;, &#039;an&#039;, &#039;and&#039;, &#039;as&#039;, &#039;but&#039;, &#039;de&#039;, &#039;nor&#039;, &#039;of&#039;, &#039;or&#039;, &#039;per&#039;, &#039;the&#039;, &#039;van&#039;, &#039;via&#039;, &#039;von&#039;); // minimal
 $s = flatten_whitespace($s);
 if (strtoupper($s) == $s) $s = ucwords($s); // disallow ALL CAPS TITLES (shouting)
 $s = preg_replace(&quot;/\b([&#039;\w]+?)(?![&#039;\w])/e&quot;, &#039;in_array(strtolower(&quot;\1&quot;), $GLOBALS[&quot;lc&quot;]) ? strtolower(&quot;\1&quot;) : (strtoupper(&quot;\1&quot;) == &quot;\1&quot; ? &quot;\1&quot; : ucfirst(strtolower(&quot;\1&quot;)));&#039;,
 $s); // words in list to lower, else Capitalize unless ALL-CAPS
 $s = preg_replace(&quot;/^(\W+)?([&#039;\w]+?)(?![&#039;\w])/e&quot;, &#039;&quot;\1&quot; . (strtoupper(&quot;\2&quot;) == &quot;\2&quot; ? &quot;\2&quot; : ucfirst(&quot;\2&quot;))&#039;,
 $s); // Capitalize first word
 $s = preg_replace(&quot;/(?&lt;/code&gt;&lt;/pre&gt;

















mmmmmm....</description>
		<content:encoded><![CDATA[<pre><code class="html">function titlecase($s) {
 $GLOBALS['lc'] = array('a', 'an', 'and', 'as', 'at', 'but', 'by', 'de', 'down', 'for', 'from', 'has', 'in', 'into', 'near', 'nor', 'of', 'off', 'onto', 'or', 'out', 'over', 'per', 'so', 'than', 'the', 'to', 'unto', 'upon', 'van', 'via', 'von', 'with', 'yet'); // , 'up'
 // $GLOBALS['lc'] = array('a', 'an', 'and', 'as', 'but', 'de', 'nor', 'of', 'or', 'per', 'the', 'van', 'via', 'von'); // minimal
 $s = flatten_whitespace($s);
 if (strtoupper($s) == $s) $s = ucwords($s); // disallow ALL CAPS TITLES (shouting)
 $s = preg_replace("/\b(['\w]+?)(?!['\w])/e", 'in_array(strtolower("\1"), $GLOBALS["lc"]) ? strtolower("\1") : (strtoupper("\1") == "\1" ? "\1" : ucfirst(strtolower("\1")));',
 $s); // words in list to lower, else Capitalize unless ALL-CAPS
 $s = preg_replace("/^(\W+)?(['\w]+?)(?!['\w])/e", '"\1" . (strtoupper("\2") == "\2" ? "\2" : ucfirst("\2"))',
 $s); // Capitalize first word
 $s = preg_replace("/(?</code></pre>
<p>mmmmmm&#8230;.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: ddzoom</title>
		<link>http://www.sitepoint.com/blogs/2005/03/15/title-case-in-php/comment-page-1/#comment-227962</link>
		<dc:creator>ddzoom</dc:creator>
		<pubDate>Wed, 18 Apr 2007 16:58:42 +0000</pubDate>
		<guid isPermaLink="false">1274596269#comment-227962</guid>
		<description>part 2...&lt;pre&gt;&lt;code class=&quot;html&quot;&gt; // Capitalize last word
 $s = preg_replace(&quot;/(?&lt;/code&gt;&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>part 2&#8230;
<pre><code class="html"> // Capitalize last word
 $s = preg_replace("/(?</code></pre></p>]]></content:encoded>
	</item>
	<item>
		<title>By: ddzoom</title>
		<link>http://www.sitepoint.com/blogs/2005/03/15/title-case-in-php/comment-page-1/#comment-227960</link>
		<dc:creator>ddzoom</dc:creator>
		<pubDate>Wed, 18 Apr 2007 16:55:34 +0000</pubDate>
		<guid isPermaLink="false">1274596269#comment-227960</guid>
		<description>try again...
&lt;pre&gt;&lt;code class=&quot;html&quot;&gt;function titlecase($s) {
 $GLOBALS[&#039;lc&#039;] = array(&#039;a&#039;, &#039;an&#039;, &#039;and&#039;, &#039;as&#039;, &#039;but&#039;, &#039;de&#039;, &#039;nor&#039;, &#039;of&#039;, &#039;or&#039;, &#039;per&#039;, &#039;the&#039;, &#039;van&#039;, &#039;via&#039;, &#039;von&#039;); // minimal
 $s = flatten_whitespace($s);

 // disallow ALL CAPS TITLES (shouting)
 if (strtoupper($s) == $s) $s = ucwords($s);

 // words in list to lower, else Capitalize unless ALL-CAPS
 $s = preg_replace(&quot;/\b([&#039;\w]+?)(?![&#039;\w])/e&quot;, &#039;in_array(strtolower(&quot;\1&quot;), $GLOBALS[&quot;lc&quot;]) ? strtolower(&quot;\1&quot;) : (strtoupper(&quot;\1&quot;) == &quot;\1&quot; ? &quot;\1&quot; : ucfirst(strtolower(&quot;\1&quot;)));&#039;,
 $s);

 // Capitalize first word
 $s = preg_replace(&quot;/^(\W+)?([&#039;\w]+?)(?![&#039;\w])/e&quot;, &#039;&quot;\1&quot; . (strtoupper(&quot;\2&quot;) == &quot;\2&quot; ? &quot;\2&quot; : ucfirst(&quot;\2&quot;))&#039;,
 $s);

 // Capitalize last word
 $s = preg_replace(&quot;/(?&lt;/code&gt;&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>try again&#8230;</p>
<pre><code class="html">function titlecase($s) {
 $GLOBALS['lc'] = array('a', 'an', 'and', 'as', 'but', 'de', 'nor', 'of', 'or', 'per', 'the', 'van', 'via', 'von'); // minimal
 $s = flatten_whitespace($s);

 // disallow ALL CAPS TITLES (shouting)
 if (strtoupper($s) == $s) $s = ucwords($s);

 // words in list to lower, else Capitalize unless ALL-CAPS
 $s = preg_replace("/\b(['\w]+?)(?!['\w])/e", 'in_array(strtolower("\1"), $GLOBALS["lc"]) ? strtolower("\1") : (strtoupper("\1") == "\1" ? "\1" : ucfirst(strtolower("\1")));',
 $s);

 // Capitalize first word
 $s = preg_replace("/^(\W+)?(['\w]+?)(?!['\w])/e", '"\1" . (strtoupper("\2") == "\2" ? "\2" : ucfirst("\2"))',
 $s);

 // Capitalize last word
 $s = preg_replace("/(?</code></pre>]]></content:encoded>
	</item>
	<item>
		<title>By: ddzoom</title>
		<link>http://www.sitepoint.com/blogs/2005/03/15/title-case-in-php/comment-page-1/#comment-227959</link>
		<dc:creator>ddzoom</dc:creator>
		<pubDate>Wed, 18 Apr 2007 16:53:32 +0000</pubDate>
		<guid isPermaLink="false">1274596269#comment-227959</guid>
		<description>I spent an afternoon playing with this, and I&#039;m sorry but your approach seems to be &lt;em&gt;way&lt;/em&gt; too simplistic. 

The following code gets a little closer, splitting words at (non-apostophe) boundaries...

&lt;pre&gt;&lt;code class=&quot;html&quot;&gt;function flatten_whitespace($s) { return preg_replace(&#039;/\s+/&#039;, &#039; &#039;, $s); } // util

function titlecase($s) {
 $GLOBALS[&#039;lc&#039;] = array(&#039;a&#039;, &#039;an&#039;, &#039;and&#039;, &#039;as&#039;, &#039;at&#039;, &#039;but&#039;, &#039;by&#039;, &#039;de&#039;, &#039;down&#039;, &#039;for&#039;, &#039;from&#039;, &#039;has&#039;, &#039;in&#039;, &#039;into&#039;, &#039;near&#039;, &#039;nor&#039;, &#039;of&#039;, &#039;off&#039;, &#039;onto&#039;, &#039;or&#039;, &#039;out&#039;, &#039;over&#039;, &#039;per&#039;, &#039;so&#039;, &#039;than&#039;, &#039;the&#039;, &#039;to&#039;, &#039;unto&#039;, &#039;upon&#039;, &#039;van&#039;, &#039;via&#039;, &#039;von&#039;, &#039;with&#039;, &#039;yet&#039;); // , &#039;up&#039;
 // $GLOBALS[&#039;lc&#039;] = array(&#039;a&#039;, &#039;an&#039;, &#039;and&#039;, &#039;as&#039;, &#039;but&#039;, &#039;de&#039;, &#039;nor&#039;, &#039;of&#039;, &#039;or&#039;, &#039;per&#039;, &#039;the&#039;, &#039;van&#039;, &#039;via&#039;, &#039;von&#039;); // minimal
 $s = flatten_whitespace($s);

 // disallow ALL CAPS TITLES (shouting)
 if (strtoupper($s) == $s) $s = ucwords($s);

 // words in list to lower, else Capitalize unless ALLCAPS
 $s = preg_replace(&quot;/\b([&#039;\w]+?)(?![&#039;\w])/e&quot;, &#039;in_array(strtolower(&quot;\1&quot;), $GLOBALS[&quot;lc&quot;]) ? strtolower(&quot;\1&quot;) : (strtoupper(&quot;\1&quot;) == &quot;\1&quot; ? &quot;\1&quot; : ucfirst(strtolower(&quot;\1&quot;)));&#039;,
 $s);

 // Capitalize first word
 $s = preg_replace(&quot;/^(\W+)?([&#039;\w]+?)(?![&#039;\w])/e&quot;, &#039;&quot;\1&quot; . (strtoupper(&quot;\2&quot;) == &quot;\2&quot; ? &quot;\2&quot; : ucfirst(&quot;\2&quot;))&#039;,
 $s);

 // Capitalize last word
 $s = preg_replace(&quot;/(?&lt;/code&gt;&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>I spent an afternoon playing with this, and I&#8217;m sorry but your approach seems to be <em>way</em> too simplistic. </p>
<p>The following code gets a little closer, splitting words at (non-apostophe) boundaries&#8230;</p>
<pre><code class="html">function flatten_whitespace($s) { return preg_replace('/\s+/', ' ', $s); } // util

function titlecase($s) {
 $GLOBALS['lc'] = array('a', 'an', 'and', 'as', 'at', 'but', 'by', 'de', 'down', 'for', 'from', 'has', 'in', 'into', 'near', 'nor', 'of', 'off', 'onto', 'or', 'out', 'over', 'per', 'so', 'than', 'the', 'to', 'unto', 'upon', 'van', 'via', 'von', 'with', 'yet'); // , 'up'
 // $GLOBALS['lc'] = array('a', 'an', 'and', 'as', 'but', 'de', 'nor', 'of', 'or', 'per', 'the', 'van', 'via', 'von'); // minimal
 $s = flatten_whitespace($s);

 // disallow ALL CAPS TITLES (shouting)
 if (strtoupper($s) == $s) $s = ucwords($s);

 // words in list to lower, else Capitalize unless ALLCAPS
 $s = preg_replace("/\b(['\w]+?)(?!['\w])/e", 'in_array(strtolower("\1"), $GLOBALS["lc"]) ? strtolower("\1") : (strtoupper("\1") == "\1" ? "\1" : ucfirst(strtolower("\1")));',
 $s);

 // Capitalize first word
 $s = preg_replace("/^(\W+)?(['\w]+?)(?!['\w])/e", '"\1" . (strtoupper("\2") == "\2" ? "\2" : ucfirst("\2"))',
 $s);

 // Capitalize last word
 $s = preg_replace("/(?</code></pre>]]></content:encoded>
	</item>
	<item>
		<title>By: Gian Luca</title>
		<link>http://www.sitepoint.com/blogs/2005/03/15/title-case-in-php/comment-page-1/#comment-194776</link>
		<dc:creator>Gian Luca</dc:creator>
		<pubDate>Mon, 05 Mar 2007 17:06:59 +0000</pubDate>
		<guid isPermaLink="false">1274596269#comment-194776</guid>
		<description>What about hyphenated words like: &quot;A client-centered approach&quot;

Aren&#039;t you supposed to capitalize each portion of the hyphenated word?</description>
		<content:encoded><![CDATA[<p>What about hyphenated words like: &#8220;A client-centered approach&#8221;</p>
<p>Aren&#8217;t you supposed to capitalize each portion of the hyphenated word?</p>]]></content:encoded>
	</item>
	<item>
		<title>By: codegreen</title>
		<link>http://www.sitepoint.com/blogs/2005/03/15/title-case-in-php/comment-page-1/#comment-192071</link>
		<dc:creator>codegreen</dc:creator>
		<pubDate>Fri, 02 Mar 2007 06:42:04 +0000</pubDate>
		<guid isPermaLink="false">1274596269#comment-192071</guid>
		<description>Awesome... thanks guys for several good solutions.</description>
		<content:encoded><![CDATA[<p>Awesome&#8230; thanks guys for several good solutions.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Nood</title>
		<link>http://www.sitepoint.com/blogs/2005/03/15/title-case-in-php/comment-page-1/#comment-169739</link>
		<dc:creator>Nood</dc:creator>
		<pubDate>Fri, 02 Feb 2007 10:10:22 +0000</pubDate>
		<guid isPermaLink="false">1274596269#comment-169739</guid>
		<description>Why such a long function just to do this!

function titleCase ($str) {
	return ucwords(strtolower($str));
}</description>
		<content:encoded><![CDATA[<p>Why such a long function just to do this!</p>
<p>function titleCase ($str) {<br />
	return ucwords(strtolower($str));<br />
}</p>]]></content:encoded>
	</item>
</channel>
</rss>
