<?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"
	>
<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>
	<pubDate>Tue, 02 Dec 2008 08:05:26 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5</generator>
		<item>
		<title>By: JimS</title>
		<link>http://www.sitepoint.com/blogs/2005/03/15/title-case-in-php/#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's a tool. Use it. Don't use it. Modify as needed. 

And ddzoom...
If you modify ALLCAP titles then the previous example where "A Title About HTML Classes" 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-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'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-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="html"&gt;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("/(?&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-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="html"&gt; // Capitalize last word
 $s = preg_replace("/(?&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-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="html"&gt;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("/(?&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-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'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="html"&gt;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("/(?&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-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: "A client-centered approach"

Aren'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-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-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>
	<item>
		<title>By: Anonymous</title>
		<link>http://www.sitepoint.com/blogs/2005/03/15/title-case-in-php/#comment-110928</link>
		<dc:creator>Anonymous</dc:creator>
		<pubDate>Wed, 29 Nov 2006 13:43:03 +0000</pubDate>
		<guid isPermaLink="false">1274596269#comment-110928</guid>
		<description>The comment I just posted got clipped. Please ignore.</description>
		<content:encoded><![CDATA[<p>The comment I just posted got clipped. Please ignore.</p>]]></content:encoded>
	</item>
</channel>
</rss>
