Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End Truncate article when not logged in?

  • This topic is empty.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #37395
    ffxpwns
    Member

    Hey, I have a (untested) truncation script. How would I make it so that the truncation script was enabled when the user was not logged in and when the user logged in they would see the full post. Thanks for the help!



    // this signifies how to truncate
    function myTruncate($string, $limit, $break=".", $pad="...")
    {
    // return with no change if string is shorter than $limit
    if(strlen($string) <= $limit) return $string;

    // is $break present between $limit and the end of the string?
    if(false !== ($breakpoint = strpos($string, $break, $limit))) {
    if($breakpoint < strlen($string) - 1) {
    $string = substr($string, 0, $breakpoint) . $pad;
    }
    }

    return $string;
    }

    And then for the length desired



    // replace 'xxx' with the number desired

    $shortdesc = myTruncate($description, XXX);
    echo "

    $shortdesc

    ";

    #100159
    ffxpwns
    Member

    Would this work?

    
    global $user;

    if (!$user->uid) {

    function myTruncate($string, $limit, $break=".", $pad="...")
    {
    // return with no change if string is shorter than $limit
    if(strlen($string) <= $limit) return $string;

    // is $break present between $limit and the end of the string?
    if(false !== ($breakpoint = strpos($string, $break, $limit))) {
    if($breakpoint < strlen($string) - 1) {
    $string = substr($string, 0, $breakpoint) . $pad;
    }
    }

    return $string;
    }

    }
    ?>
Viewing 2 posts - 1 through 2 (of 2 total)
  • The forum ‘Back End’ is closed to new topics and replies.