Word count like function Ver.1.0! This function can count your input text

Posted on Aug 23, 2011 in PHP

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 [...]

Trim Function

Posted on Aug 23, 2011 in PHP

Trim Function Left – ltrim() function <?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 [...]

This function allows you to take any string and split it into fairly even pieces

Posted on Aug 23, 2011 in PHP

This function allows you to take any string and split it into fairly even pieces <? function breakString($str=”", $pieces=”") { // Find out how big the string is $len = strlen($str); // String size can’t be less than pieces if ($len < $pieces) { $ary[0] = “String Size is less than Number of Pieces”; return [...]

Sub String Replace

Posted on Aug 23, 2011 in PHP

Sub String Replace <?php $var = ‘ABCDEFGH:/MNRPQR/’; echo “Original: $var<hr>\n”; /* These two examples replace all of $var with ‘bob’. */ echo substr_replace($var, ‘bob’, 0) . “<br>\n”; echo substr_replace($var, ‘bob’, 0, strlen($var)) . “<br>\n”; /* Insert ‘bob’ right at the beginning of $var. */ echo substr_replace($var, ‘bob’, 0, 0) . “<br>\n”; /* These next two [...]

Sorting Strings

Posted on Aug 23, 2011 in PHP

Sorting Strings <?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); ?> /* Output Standard string comparison Array ( [0] => img1.png [1] => img10.png [2] => img12.png [3] => img2.png ) Natural order string comparison Array ( [0] => img1.png [1] => img2.png [2] [...]

Short text sample from long text articles

Posted on Aug 23, 2011 in PHP

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. <?php function shortenText(&$source_text, $word_count) { $word_count++; $long_enough = TRUE; if ((trim($source_text) != “”) && ($word_count > 0)) { $split_text = explode(” “, [...]

Page 1 of 13812345Next Page »