Hi friends !! It is the function to display limited characters from a string without cutting the last word. If we use only substr the last word is not displayed properly. Using this custom function, we can solve this.
We just have to pass the string and the limit to the function. It will return the result string. Thanks !!
Call function like this : -
echo showstring('This is a little blog of php functions and source codes',30);
We just have to pass the string and the limit to the function. It will return the result string. Thanks !!
function showstring($string,$pos){
$data=substr($string,$pos,1);
if($data!=" "){
while($data!=" "){
@$pos=$pos+1;
$data=substr($string,$pos,1);
}
}
$data=substr($string,0,$pos);
echo $data;
}
Call function like this : -
echo showstring('This is a little blog of php functions and source codes',30);
Posting Komentar