<?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>CyberDairy Solutions &#187; Code Snippets</title>
	<atom:link href="http://cyberdairy.com/category/code-snippets/feed/" rel="self" type="application/rss+xml" />
	<link>http://cyberdairy.com</link>
	<description></description>
	<lastBuildDate>Wed, 16 May 2012 06:57:19 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Word count like function Ver.1.0! This function can count your input text</title>
		<link>http://cyberdairy.com/word-count-function-ver-1-0-function-count-input-text/</link>
		<comments>http://cyberdairy.com/word-count-function-ver-1-0-function-count-input-text/#comments</comments>
		<pubDate>Tue, 23 Aug 2011 10:59:48 +0000</pubDate>
		<dc:creator>coder</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://cyberdairy.com/?p=3156</guid>
		<description><![CDATA[Word count like function Ver.1.0! This function can count your input text and display only part of it (like a description) without cutting words in half function smart_text ($text_input_var[string] ,text_length[int]) { $strip_content=stripslashes($content); $all_content=strlen("$strip_content"); $standard_content=substr($strip_content ,$text_length); $compare=stristr($standard_content ," "); $minus_content=strlen("$compare"); $result_content=$all_content-$minus_content; $display_content=substr($strip_content ,0, $result_content); $striped_content=stripslashes($display_content); echo nl2br($striped_content); } For example i insert a 300 words test [...]]]></description>
			<content:encoded><![CDATA[<pre>Word count like function Ver.1.0! This function can count your input text
and display only part of it (like a description) without cutting words in half

  function smart_text ($text_input_var[string] ,text_length[int]) 
  { 
      $strip_content=stripslashes($content); 
      $all_content=strlen("$strip_content"); 

      $standard_content=substr($strip_content ,$text_length); 
      $compare=stristr($standard_content ," "); 
      $minus_content=strlen("$compare"); 
                 
      $result_content=$all_content-$minus_content; 
      $display_content=substr($strip_content ,0, $result_content); 
                 
      $striped_content=stripslashes($display_content);   
      echo nl2br($striped_content); 
  } 

For example i insert a 300 words test but only want about 3 rows of it to be displayed 
without cutting words in half. 
                 
function smart_text($text,200) 

Displayed result will be the first 200 letters of the text plus the letters till the first space 
char.</pre>]]></content:encoded>
			<wfw:commentRss>http://cyberdairy.com/word-count-function-ver-1-0-function-count-input-text/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Trim Function</title>
		<link>http://cyberdairy.com/trim-function/</link>
		<comments>http://cyberdairy.com/trim-function/#comments</comments>
		<pubDate>Tue, 23 Aug 2011 10:59:32 +0000</pubDate>
		<dc:creator>coder</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://cyberdairy.com/?p=3154</guid>
		<description><![CDATA[Trim Function Left - ltrim() function &#60;?php $text = "\t\tThese are a few words ... "; $trimmed = ltrim($text); // $trimmed = "These are a few words ... " $trimmed = ltrim($text," \t."); // $trimmed = "These are a few words ... " $clean = ltrim($binary,"x00..x1F"); // trim the ASCII control characters at the beginning [...]]]></description>
			<content:encoded><![CDATA[<pre>Trim Function

Left - ltrim() function 
&lt;?php 

$text = "\t\tThese are a few words <img src='http://cyberdairy.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  ...  "; 
$trimmed = ltrim($text); 
// $trimmed = "These are a few words <img src='http://cyberdairy.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  ...  " 
$trimmed = ltrim($text," \t."); 
// $trimmed = "These are a few words <img src='http://cyberdairy.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  ...  " 
$clean = ltrim($binary,"x00..x1F"); 
// trim the ASCII control characters at the beginning of $binary 
// (from 0 to 31 inclusive) 

?&gt; 

Right - rtrim() function 
&lt;?php 

$text = "\t\tThese are a few words <img src='http://cyberdairy.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  ...  "; 
$trimmed = rtrim($text); 
// $trimmed = "\t\tThese are a few words <img src='http://cyberdairy.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  ..." 
$trimmed = rtrim($text," \t."); 
// $trimmed = "\t\tThese are a few words <img src='http://cyberdairy.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> " 
$clean = rtrim($binary,"x00..x1F"); 
// trim the ASCII control characters at the end of $binary 
// (from 0 to 31 inclusive) 

?&gt;</pre>]]></content:encoded>
			<wfw:commentRss>http://cyberdairy.com/trim-function/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>This function allows you to take any string and split it into fairly even pieces</title>
		<link>http://cyberdairy.com/function-string-split-pieces/</link>
		<comments>http://cyberdairy.com/function-string-split-pieces/#comments</comments>
		<pubDate>Tue, 23 Aug 2011 10:59:18 +0000</pubDate>
		<dc:creator>coder</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://cyberdairy.com/?p=3152</guid>
		<description><![CDATA[This function allows you to take any string and split it into fairly even pieces &#60;? function breakString($str="", $pieces="") { // Find out how big the string is $len = strlen($str); // String size can't be less than pieces if ($len &#60; $pieces) { $ary[0] = "String Size is less than Number of Pieces"; return [...]]]></description>
			<content:encoded><![CDATA[<pre>This function allows you to take any string and split it into fairly even pieces

&lt;? 

function breakString($str="", $pieces="") { 

// Find out how big the string is 
$len = strlen($str); 

// String size can't be less than pieces 
if ($len &lt; $pieces) { 
    $ary[0] = "String Size is less than Number of Pieces"; 
    return $ary; 
} 

// Find out how big each piece should be 
$lim = $len / $pieces; 
$start = 0; 
$i = 0; 
$l = 0; 

// Split string into individual characters 
for ($k = 0; $k &lt; $len; $k++) { 
     $x = $k + 1; 
     $g[$k] = substr($str,$k,1); 
} 

// Start Making Pieces 
while ($i &lt; $pieces) { 
    
// Glue Pieces Back Togeather 
   for ($j = $start; $j &lt; $lim; $j++) { 
       $tmp = $tmp . $g[$l]; 
       $l++; 
   } 

// Back up one character in the array 
   $x = $l - 1; 

// If Last Charecter is NOT a space, AND this is NOT the last piece, 
// Go until the next  space is found 
   while (($g[$x] != " ") AND ($i != $pieces -1)) { 
     $tmp = $tmp . $g[$l]; 
     $g[$x] = $g[$l]; 
     $l++; 
   } 

// Move this String into array piece 
   $ary[$i] = $tmp; 
// Reset String 
   $tmp = ""; 
   $i++; 
} 

// Output String 
   return $ary; 

} 

$text = "this is a little test with php3, MYSQL and Apache on my webserver. It works fine but i have to learn a lot about php3!"; 
echo("&lt;b&gt;$text&lt;/b&gt;&lt;br&gt;&lt;br&gt;"); 

$now = breakString($text, 3); 

$sze = sizeof($now); 

for ($ii = 0; $ii &lt; $sze; $ii++) { 
     echo("$now[$ii]&lt;br&gt;"); 
} 

?&gt;</pre>]]></content:encoded>
			<wfw:commentRss>http://cyberdairy.com/function-string-split-pieces/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sub String Replace</title>
		<link>http://cyberdairy.com/string-replace/</link>
		<comments>http://cyberdairy.com/string-replace/#comments</comments>
		<pubDate>Tue, 23 Aug 2011 10:58:58 +0000</pubDate>
		<dc:creator>coder</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://cyberdairy.com/?p=3150</guid>
		<description><![CDATA[Sub String Replace &#60;?php $var = 'ABCDEFGH:/MNRPQR/'; echo "Original: $var&#60;hr&#62;\n"; /* These two examples replace all of $var with 'bob'. */ echo substr_replace($var, 'bob', 0) . "&#60;br&#62;\n"; echo substr_replace($var, 'bob', 0, strlen($var)) . "&#60;br&#62;\n"; /* Insert 'bob' right at the beginning of $var. */ echo substr_replace($var, 'bob', 0, 0) . "&#60;br&#62;\n"; /* These next two [...]]]></description>
			<content:encoded><![CDATA[<pre>Sub String Replace

&lt;?php 
$var = 'ABCDEFGH:/MNRPQR/'; 
echo "Original: $var&lt;hr&gt;\n"; 

/* These two examples replace all of $var with 'bob'. */ 
echo substr_replace($var, 'bob', 0) . "&lt;br&gt;\n"; 
echo substr_replace($var, 'bob', 0, strlen($var)) . "&lt;br&gt;\n"; 

/* Insert 'bob' right at the beginning of $var. */ 
echo substr_replace($var, 'bob', 0, 0) . "&lt;br&gt;\n"; 

/* These next two replace 'MNRPQR' in $var with 'bob'. */ 
echo substr_replace($var, 'bob', 10, -1) . "&lt;br&gt;\n"; 
echo substr_replace($var, 'bob', -7, -1) . "&lt;br&gt;\n"; 

/* Delete 'MNRPQR' from $var. */ 
echo substr_replace($var, '', 10, -1) . "&lt;br&gt;\n"; 
?&gt;</pre>]]></content:encoded>
			<wfw:commentRss>http://cyberdairy.com/string-replace/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sorting Strings</title>
		<link>http://cyberdairy.com/sorting-strings/</link>
		<comments>http://cyberdairy.com/sorting-strings/#comments</comments>
		<pubDate>Tue, 23 Aug 2011 10:58:43 +0000</pubDate>
		<dc:creator>coder</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://cyberdairy.com/?p=3148</guid>
		<description><![CDATA[Sorting Strings &#60;?php $arr1 = $arr2 = array("img12.png","img10.png","img2.png","img1.png"); echo "Standard string comparison\n"; usort($arr1,"strcmp"); print_r($arr1); echo "\nNatural order string comparison\n"; usort($arr2,"strnatcmp"); print_r($arr2); ?&#62; /* Output Standard string comparison Array ( [0] =&#62; img1.png [1] =&#62; img10.png [2] =&#62; img12.png [3] =&#62; img2.png ) Natural order string comparison Array ( [0] =&#62; img1.png [1] =&#62; img2.png [2] [...]]]></description>
			<content:encoded><![CDATA[<pre>Sorting Strings

&lt;?php 
$arr1 = $arr2 = array("img12.png","img10.png","img2.png","img1.png"); 
echo "Standard string comparison\n"; 
usort($arr1,"strcmp"); 
print_r($arr1); 
echo "\nNatural order string comparison\n"; 
usort($arr2,"strnatcmp"); 
print_r($arr2); 
?&gt; 


/* Output 
Standard string comparison 
Array 
( 
    [0] =&gt; img1.png 
    [1] =&gt; img10.png 
    [2] =&gt; img12.png 
    [3] =&gt; img2.png 
) 

Natural order string comparison 
Array 
( 
    [0] =&gt; img1.png 
    [1] =&gt; img2.png 
    [2] =&gt; img10.png 
    [3] =&gt; img12.png 
) 
*/</pre>]]></content:encoded>
			<wfw:commentRss>http://cyberdairy.com/sorting-strings/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Short text sample from long text articles</title>
		<link>http://cyberdairy.com/short-text-sample-long-text-articles/</link>
		<comments>http://cyberdairy.com/short-text-sample-long-text-articles/#comments</comments>
		<pubDate>Tue, 23 Aug 2011 10:58:25 +0000</pubDate>
		<dc:creator>coder</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://cyberdairy.com/?p=3146</guid>
		<description><![CDATA[Short text sample from long text articles When you want to show a snippet of text for an article but dont want to cut off words in the middle, use this little function. &#60;?php function shortenText(&#38;$source_text, $word_count) { $word_count++; $long_enough = TRUE; if ((trim($source_text) != "") &#38;&#38; ($word_count &#62; 0)) { $split_text = explode(" ", [...]]]></description>
			<content:encoded><![CDATA[<pre>Short text sample from long text articles

When you want to show a snippet of text for an article but dont want to cut off words in the middle, use this little function. 

&lt;?php 

function shortenText(&amp;$source_text, $word_count) 
{ 
    $word_count++; 
    $long_enough = TRUE; 
    if ((trim($source_text) != "") &amp;&amp; ($word_count &gt; 0)) 
    { 
        $split_text = explode(" ", $source_text, $word_count); 
        if (sizeof($split_text) &lt; $word_count) 
        { 
            $long_enough = FALSE; 
        } 
        else 
        { 
            array_pop($split_text); 
            $source_text = implode(" ", $split_text); 
        } 
    } 
    return $long_enough; 
} 

// sample use 
$long_text="a b c d e f g h i j k l m n o p q r s t u v w x y z"; 
$short_text=$long_text; 
$more_text_available=shortenText($short_text, 20); 

echo $short_text; 
if($more_text_available) 
{ 
  echo '&lt;a href="URL to larger text"&gt;more...&lt;/a&gt;'; 
} 

?&gt;
The text is shortened to the required word length. The returned value tells us if the original text is shorter than the required word length. This can then be used to determine if we want to use a link or script to display the full article.</pre>]]></content:encoded>
			<wfw:commentRss>http://cyberdairy.com/short-text-sample-long-text-articles/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

