<?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>Blog by Andreas Glaser &#187; Strings</title>
	<atom:link href="http://www.andreas-glaser.com/tag/strings/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.andreas-glaser.com</link>
	<description>Development, Technology and such...</description>
	<lastBuildDate>Wed, 18 May 2011 23:16:12 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>(PHP) Remove redundant spaces</title>
		<link>http://www.andreas-glaser.com/2009/03/13/php-remove-redundant-spaces/</link>
		<comments>http://www.andreas-glaser.com/2009/03/13/php-remove-redundant-spaces/#comments</comments>
		<pubDate>Fri, 13 Mar 2009 15:09:40 +0000</pubDate>
		<dc:creator>Andreas Glaser</dc:creator>
				<category><![CDATA[Computer]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Function]]></category>
		<category><![CDATA[Knowledge]]></category>
		<category><![CDATA[Strings]]></category>

		<guid isPermaLink="false">http://www.andreas-glaser.com/?p=342</guid>
		<description><![CDATA[Function Removes redundant spaces within a string. Code ?View Code PHP1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 // :: JaZz phpFramework // :: V1.0 // :: 13/03/2009 15:24:08 function remove_redundant_spaces&#40;$String = ''&#41; &#123; // :: Initalize Variables $Result = NULL; for [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Function</strong></p>
<p>Removes redundant spaces within a string<strong>.</strong></p>
<p><strong>Code</strong></p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p342code3'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p3423"><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
</pre></td><td class="code" id="p342code3"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// :: JaZz phpFramework</span>
<span style="color: #666666; font-style: italic;">// :: V1.0</span>
<span style="color: #666666; font-style: italic;">// :: 13/03/2009 15:24:08</span>
<span style="color: #000000; font-weight: bold;">function</span> remove_redundant_spaces<span style="color: #009900;">&#40;</span><span style="color: #000088;">$String</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  <span style="color: #666666; font-style: italic;">// :: Initalize Variables</span>
  <span style="color: #000088;">$Result</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">NULL</span><span style="color: #339933;">;</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;">&amp;</span>lt<span style="color: #339933;">;</span> <a href="http://www.php.net/strlen"><span style="color: #990000;">strlen</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$String</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><a href="http://www.php.net/substr"><span style="color: #990000;">substr</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$String</span><span style="color: #339933;">,</span> <span style="color: #000088;">$i</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">' '</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #000088;">$Result</span> <span style="color: #339933;">.=</span> <a href="http://www.php.net/trim"><span style="color: #990000;">trim</span></a><span style="color: #009900;">&#40;</span><a href="http://www.php.net/substr"><span style="color: #990000;">substr</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$String</span><span style="color: #339933;">,</span> <span style="color: #000088;">$i</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</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;">while</span> <span style="color: #009900;">&#40;</span><a href="http://www.php.net/substr"><span style="color: #990000;">substr</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$String</span><span style="color: #339933;">,</span> <span style="color: #000088;">$i</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">' '</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$i</span><span style="color: #339933;">++;</span>
      <span style="color: #009900;">&#125;</span>
      <span style="color: #000088;">$Result</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">' '</span><span style="color: #339933;">;</span>
      <span style="color: #000088;">$i</span><span style="color: #339933;">--;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #b1b100;">return</span> <span style="color: #000088;">$Result</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p><strong><br />
</strong></p>
<p><strong>Usage</strong></p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p342code4'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p3424"><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code" id="p342code4"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$String</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'This    string   contains    redundant    spaces'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$NewString</span> <span style="color: #339933;">=</span> remove_redundant_spaces<span style="color: #009900;">&#40;</span><span style="color: #000088;">$String</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$NewString</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Output: This string conains redundant spaces</span></pre></td></tr></table></div>

<p><em><br />
<strong>So long,<br />
JaZz</strong></em></p>
<fb:like href='http://www.andreas-glaser.com/2009/03/13/php-remove-redundant-spaces/' send='' layout='standard' show_faces='true' width='450' height='65' action='like' colorscheme='light' font='lucida+grande'></fb:like>]]></content:encoded>
			<wfw:commentRss>http://www.andreas-glaser.com/2009/03/13/php-remove-redundant-spaces/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

