Tutorials Home Scripts Home

Limit Characters From Your Text

Limit Characters From Your Text

Syntax

text_limit($str,$limit);
This php function helps you limit displaying characters form you text and not cut your word.

How It Work

1. Define how many characters you want to display.
2. Find what is the last character displaying.
3. If the last character displaying is not " " (space) then go to next character until we found it.
4. Display your message

the function

function text_limit($str,$limit=10)
{
if(stripos($str," "))
{
$ex_str=explode(" ",$str);
if(count($ex_str)>$limit)
{
for($i=0;$i<$limit;$i++)
{
$str_s.=$ex_str[$i]." ";
}
return $str_s;
}
else{
return $str;
}
}else{
return $str;
}
}

Parameters

string
The input string.limit

Define how many characters you want to displayExample #1

<?php
$text = "Jooria Refresh Your Website";
echo text_limit($text,2);
?>
RETURN: Jooria Refresh this is two words

Category: Website Programming | Views: 5,064 | on: September 14, 2009 | by: jooria
“Subscribe and get the new Tutorials”

Enter your email address:

Last 1 Responses

Comment form

  1. dilandinga About 4 months ago
    I bookmarked this link. Thank you for good job!

Leave a Comment

Comment form