<?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/"
xmlns:series="http://unfoldingneurons.com/"
> <channel><title>Comments on: Pretty Word Wrapper with MooTools or&#160;PHP</title> <atom:link href="http://davidwalsh.name/word-wrap-mootools-php/feed" rel="self" type="application/rss+xml" /><link>http://davidwalsh.name/word-wrap-mootools-php</link> <description>Legendary scribbles about JavaScript, HTML5, AJAX, PHP, CSS, and ∞.</description> <lastBuildDate>Thu, 24 May 2012 07:34:33 +0000</lastBuildDate> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.3.2</generator> <item><title>By: Ken Hawkins</title><link>http://davidwalsh.name/word-wrap-mootools-php#comment-31033</link> <dc:creator>Ken Hawkins</dc:creator> <pubDate>Thu, 15 Mar 2012 10:54:50 +0000</pubDate> <guid
isPermaLink="false">http://davidwalsh.name/?p=3505#comment-31033</guid> <description>Fiddlesticks, it garbled my code paste (I even used the &lt;code&gt; tags!) See it here http://pastebin.com/DhVKZu1T</description> <content:encoded><![CDATA[<p>Fiddlesticks, it garbled my code paste (I even used the <code> tags!) See it here <a
href="http://pastebin.com/DhVKZu1T" rel="nofollow">http://pastebin.com/DhVKZu1T</a></code></p> ]]></content:encoded> </item> <item><title>By: Ken Hawkins</title><link>http://davidwalsh.name/word-wrap-mootools-php#comment-31032</link> <dc:creator>Ken Hawkins</dc:creator> <pubDate>Thu, 15 Mar 2012 10:53:14 +0000</pubDate> <guid
isPermaLink="false">http://davidwalsh.name/?p=3505#comment-31032</guid> <description>Works fine for us with PHP, example in the h1 headline at  http://charleston.thedigitel.com/politics/folly-beach-bans-discrimination-based-sexual-orien-38425-0315I also modified it a bit to allow for us to concat the last three words if there are six or more words (good for our headline setup), code below.&lt;code&gt;
/**
* Prevent widows
* based off http://davidwalsh.name/word-wrap-mootools-php
*
* If there are 6+ words it will concat three words with &#039;&#160;&#039;
* otherwise if 3+ it will concat two words at end
*
* The longWords can be disabled by setting $longWords
* to a high value (i.e. 99999) when calling the function
*
**/
function word_wrapper($text,$longWords = 6,$minWords = 3) {
$return = $text;
$arr = explode(&#039; &#039;,$text);
if(count($arr) &gt;= $longWords) {
$arr[count($arr) - 2].= &#039;&#160;&#039;.$arr[count($arr) - 1];
array_pop($arr);
$arr[count($arr) - 2].= &#039;&#160;&#039;.$arr[count($arr) - 1];
array_pop($arr);
$return = implode(&#039; &#039;,$arr);
} elseif(count($arr) &gt;= $minWords) {
$arr[count($arr) - 2].= &#039;&#160;&#039;.$arr[count($arr) - 1];
array_pop($arr);
$return = implode(&#039; &#039;,$arr);
}
return $return;
}
&lt;/code&gt;</description> <content:encoded><![CDATA[<p>Works fine for us with PHP, example in the h1 headline at <a
href="http://charleston.thedigitel.com/politics/folly-beach-bans-discrimination-based-sexual-orien-38425-0315" rel="nofollow">http://charleston.thedigitel.com/politics/folly-beach-bans-discrimination-based-sexual-orien-38425-0315</a></p><p>I also modified it a bit to allow for us to concat the last three words if there are six or more words (good for our headline setup), code below.</p><p><code><br
/> /**<br
/> * Prevent widows<br
/> * based off <a
href="http://davidwalsh.name/word-wrap-mootools-php" rel="nofollow">http://davidwalsh.name/word-wrap-mootools-php</a><br
/> *<br
/> * If there are 6+ words it will concat three words with '&nbsp;'<br
/> * otherwise if 3+ it will concat two words at end<br
/> *<br
/> * The longWords can be disabled by setting $longWords<br
/> * to a high value (i.e. 99999) when calling the function<br
/> *<br
/> **/<br
/> function word_wrapper($text,$longWords = 6,$minWords = 3) {<br
/> $return = $text;<br
/> $arr = explode(' ',$text);<br
/> if(count($arr) &gt;= $longWords) {<br
/> $arr[count($arr) - 2].= '&nbsp;'.$arr[count($arr) - 1];<br
/> array_pop($arr);<br
/> $arr[count($arr) - 2].= '&nbsp;'.$arr[count($arr) - 1];<br
/> array_pop($arr);<br
/> $return = implode(' ',$arr);<br
/> } elseif(count($arr) &gt;= $minWords) {<br
/> $arr[count($arr) - 2].= '&nbsp;'.$arr[count($arr) - 1];<br
/> array_pop($arr);<br
/> $return = implode(' ',$arr);<br
/> }<br
/> return $return;<br
/> }</p><p> </code></p> ]]></content:encoded> </item> <item><title>By: Simon</title><link>http://davidwalsh.name/word-wrap-mootools-php#comment-27673</link> <dc:creator>Simon</dc:creator> <pubDate>Sat, 19 Nov 2011 18:07:14 +0000</pubDate> <guid
isPermaLink="false">http://davidwalsh.name/?p=3505#comment-27673</guid> <description>I can&#039;t get this to work. Am I doing something wrong?I add the php code into the head but it doesn&#039;t add a non-break-spaceCan anyone point me to a working example?</description> <content:encoded><![CDATA[<p>I can&#8217;t get this to work. Am I doing something wrong?</p><p>I add the php code into the head but it doesn&#8217;t add a non-break-space</p><p>Can anyone point me to a working example?</p> ]]></content:encoded> </item> <item><title>By: Greg</title><link>http://davidwalsh.name/word-wrap-mootools-php#comment-11890</link> <dc:creator>Greg</dc:creator> <pubDate>Tue, 15 Sep 2009 13:45:09 +0000</pubDate> <guid
isPermaLink="false">http://davidwalsh.name/?p=3505#comment-11890</guid> <description>You can stream line you code a little by changing thearr[arr.length - 2] += &#039;&#160;&#039; + arr[arr.length - 1];arr.pop();with
arr[arr.length - 2] += &#039;&#160;&#039; + arr.pop();You can do the same with the PHP too.since the array Pop method both removes the last item in the array AND returns its value.  Though this will not make a huge impact on the performance of the code it is code practice.</description> <content:encoded><![CDATA[<p>You can stream line you code a little by changing the</p><p>arr[arr.length - 2] += &#8216;&nbsp;&#8217; + arr[arr.length - 1];</p><p>arr.pop();</p><p>with<br
/> arr[arr.length - 2] += &#8216;&nbsp;&#8217; + arr.pop();</p><p>You can do the same with the PHP too.</p><p>since the array Pop method both removes the last item in the array AND returns its value.  Though this will not make a huge impact on the performance of the code it is code practice.</p> ]]></content:encoded> </item> <item><title>By: Dutchie</title><link>http://davidwalsh.name/word-wrap-mootools-php#comment-11585</link> <dc:creator>Dutchie</dc:creator> <pubDate>Fri, 28 Aug 2009 18:56:41 +0000</pubDate> <guid
isPermaLink="false">http://davidwalsh.name/?p=3505#comment-11585</guid> <description>Hmm.. I like this idea, but still the www is not a thing like print is in combination with InDesign (I reffuse to mention Quark, lol), which have advanced widow cut rules etc. build in. I mean, it&#039;s not always appropriate to move the two last words to the next line as a default in various languages/situations.. then I rather blame the browser&#039;s neanderthaler rudeness :)But again, it&#039;s an original idea which probably makes the headlines in most cases a bit nicer, and the JS is small (and php is fast).</description> <content:encoded><![CDATA[<p>Hmm.. I like this idea, but still the www is not a thing like print is in combination with InDesign (I reffuse to mention Quark, lol), which have advanced widow cut rules etc. build in. I mean, it&#8217;s not always appropriate to move the two last words to the next line as a default in various languages/situations.. then I rather blame the browser&#8217;s neanderthaler rudeness :)</p><p>But again, it&#8217;s an original idea which probably makes the headlines in most cases a bit nicer, and the JS is small (and php is fast).</p> ]]></content:encoded> </item> <item><title>By: Adriaan</title><link>http://davidwalsh.name/word-wrap-mootools-php#comment-11579</link> <dc:creator>Adriaan</dc:creator> <pubDate>Fri, 28 Aug 2009 15:41:04 +0000</pubDate> <guid
isPermaLink="false">http://davidwalsh.name/?p=3505#comment-11579</guid> <description>Ineresting approach, I use a little function that cuts the text off after a certain amount of characters and then adds ... to it.  Of course I&#039;m checking correctly for things like, cutting at the first space before the max amount of chars, taking care of commas and hyphens, etc</description> <content:encoded><![CDATA[<p>Ineresting approach, I use a little function that cuts the text off after a certain amount of characters and then adds &#8230; to it.  Of course I&#8217;m checking correctly for things like, cutting at the first space before the max amount of chars, taking care of commas and hyphens, etc</p> ]]></content:encoded> </item> <item><title>By: David Walsh</title><link>http://davidwalsh.name/word-wrap-mootools-php#comment-11578</link> <dc:creator>David Walsh</dc:creator> <pubDate>Fri, 28 Aug 2009 14:44:45 +0000</pubDate> <guid
isPermaLink="false">http://davidwalsh.name/?p=3505#comment-11578</guid> <description>&lt;p&gt;Thanks Francis!  Stupid WordPress...&lt;/p&gt;</description> <content:encoded><![CDATA[<p>Thanks Francis!  Stupid WordPress&#8230;</p> ]]></content:encoded> </item> <item><title>By: Francis</title><link>http://davidwalsh.name/word-wrap-mootools-php#comment-11577</link> <dc:creator>Francis</dc:creator> <pubDate>Fri, 28 Aug 2009 14:43:02 +0000</pubDate> <guid
isPermaLink="false">http://davidwalsh.name/?p=3505#comment-11577</guid> <description>Took me a while to understand what this was doing until I noticed that the &amp;nbsp is replaced by a blank space &#039; &#039; in the code!
Should read: $arr[count($arr) - 2].= &#039;&amp;nbsp&#039;.$arr[count($arr) - 1];</description> <content:encoded><![CDATA[<p>Took me a while to understand what this was doing until I noticed that the &amp;nbsp is replaced by a blank space &#8216; &#8216; in the code!<br
/> Should read: $arr[count($arr) - 2].= &#8216;&amp;nbsp&#8217;.$arr[count($arr) - 1];</p> ]]></content:encoded> </item> <item><title>By: David Walsh</title><link>http://davidwalsh.name/word-wrap-mootools-php#comment-11576</link> <dc:creator>David Walsh</dc:creator> <pubDate>Fri, 28 Aug 2009 14:40:58 +0000</pubDate> <guid
isPermaLink="false">http://davidwalsh.name/?p=3505#comment-11576</guid> <description>&lt;p&gt;@Chris the Developer:  How so?&lt;/p&gt;</description> <content:encoded><![CDATA[<p>@Chris the Developer:  How so?</p> ]]></content:encoded> </item> <item><title>By: Chris the Developer</title><link>http://davidwalsh.name/word-wrap-mootools-php#comment-11575</link> <dc:creator>Chris the Developer</dc:creator> <pubDate>Fri, 28 Aug 2009 14:36:20 +0000</pubDate> <guid
isPermaLink="false">http://davidwalsh.name/?p=3505#comment-11575</guid> <description>Wouldn&#039;t it be more safe-mode friendly if you used document.getElements() instead of $$?</description> <content:encoded><![CDATA[<p>Wouldn&#8217;t it be more safe-mode friendly if you used document.getElements() instead of $$?</p> ]]></content:encoded> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: enhanced (User agent is rejected)
Database Caching 3/7 queries in 0.013 seconds using disk: basic
Object Caching 805/805 objects using disk: basic

Served from: davidwalsh.name @ 2012-05-24 03:47:42 -->
