Latest Post

Short Text in PHP

Short Text in PHP

Short Text in PHP


This is function for Short Text and you are use this function.

<?php
function shorter($text, $chars_limit)
{
    // Check if length is larger than the character limit
    if (strlen($text) > $chars_limit)
    {
        // If so, cut the string at the character limit
        $new_text = substr($text, 0, $chars_limit);
        // Trim off white space
        $new_text = trim($new_text);
        // Add at end of text ...
        return $new_text . "...";
    }
    // If not just return the text as is
    else
    {
    return $text;
    }
}
?>

This code is for Display you page.

<?php echo shorter($row['database filed name'],105) ?>

No comments