Powered by InterCreatives | Site Map
Search:
NewSourceMedia Popular Tutorials: PHP Javascripts Web Hosting
SoftwareTutorials
CATEGORIES
Job Listings
 
Home / PHP / Content Management

Portion() function for trimming text

Published by: Alex


I created this function to display a portion of listings on my home page under their related links to the full body of content.

This can helps your visitor to find the content faster as well as helps search engine better index your web site.

Portion() Code:

<?
// function starts here
function portion($max_len,$str){
if(!$max_len)
$max_len = 12; // defult max length of characters including blank spaces
if (strlen($str) > $max_len){
echo substr("$str", 0, $max_len)."..."; // your portion of text with traling dots "..."
}
else
echo $str;
}
// function code end here

$str = "Hello World"; // edit or delete this line for your use
portion(7,"$str"); // call the function ( this will return "Hello W..." )

?>


Next PHP Page:
1  2  3  4  5  6  7  8  9  10  11  12  13  14  15  16  17  18  19  20  [21]  22  23  24  25  26  27  28  29  30  31  32 





Hosting by iPowerWeb.com - 50 Gb for $7.95