Forum Replies Created

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter karasunouta

    (@karasunouta)

    Thank you for your immediate correspondence.
    Sorry for I’m lacking time to check now, but thanking and trusting in your long time stable work overwrite my one star with four star for now.
    Relieved!

    Thread Starter karasunouta

    (@karasunouta)

    Modified a little:
    strrpos -> $posFunc

    //Shrink a tweet and accompanying URL down to 140 chars.
    function set_tweet_length($message, $url, $twitter_hashtags="", $hashtag_length=0) {
    
        $lenFunc = function_exists('mb_strlen') ? 'mb_strlen' : 'strlen';
        $posFunc = function_exists('mb_strrpos') ? 'mb_strrpos' : 'strrpos';
        $subFunc = function_exists('mb_substr') ? 'mb_substr' : 'substr';
        $tags = $twitter_hashtags;
        $message_length = $lenFunc($message);
        $url_length = $lenFunc($url);
        //$cur_length = $lenFunc($tags);
        if ($hashtag_length == 0)
            $hashtag_length = $lenFunc($tags);
    
        if ($twitter_hashtags != "") {
            if ($lenFunc($tags) > $hashtag_length) {
                $tags = $subFunc($tags, 0, $hashtag_length);
                $tags = $subFunc($tags, 0, $posFunc($tags, ' '));
            }
            $hashtag_length = $lenFunc($tags);
        }
    
        if ($message_length + $url_length + $hashtag_length > 140) {
    
            $shorten_message_to = 140 - $url_length - $hashtag_length;
            $shorten_message_to = $shorten_message_to - 4;
    //$message = $message." ";
            if ($lenFunc($message) > $shorten_message_to) {
                $message = $subFunc($message, 0, $shorten_message_to);
                $message = $subFunc($message, 0, $posFunc($message, ' '));
            }
            $message = $message . "...";
        }
        return $message . " " . $url . " " . $tags;
    }
Viewing 2 replies - 1 through 2 (of 2 total)