+ Reply to Thread
Results 1 to 8 of 8

Thread: URL shortened...

  1. #1
    Senior Member R1Swedie is on a distinguished road
    Join Date
    Oct 2003
    Age
    28
    Posts
    118

    URL shortened...

    Hey

    I see vBulletin have shortens URL's that are longer than a certain number of characters. Can you possibly share with me what the script is to do this?

    Currently I just have a script to turn URL's into HREF's, but since some URL's are scary long and messed up the layout I wish to shorten the URL down, just like vBulletin does (http://www.sporthoj.com/forum/for...alongurl) .. like that with the 3 dots.

    Thanks!

  2. #2
    Senior Member R1Swedie is on a distinguished road
    Join Date
    Oct 2003
    Age
    28
    Posts
    118
    or you don't reveal such big secrets? :/

  3. #3
    Senior Member noppid is on a distinguished road
    Join Date
    May 2003
    Posts
    600
    Buffer the URL and for the href echo the whole url, for the url text echo the var shortened plus the 3 dots.
    Computer Help Forum
    An informed rider makes their first destination the motorcycle forum at rider info.

  4. #4
    Senior Member rebby is on a distinguished road rebby's Avatar
    Join Date
    Mar 2001
    Location
    Hugo, MN
    Age
    30
    Posts
    220
    There probably isn't a script to do this. It's as easy as ->
    PHP Code:
    $url='http://www.vbulletin.com/forum/showthread.php?t=91514';
    $numchars=15;
    echo 
    '<a href="' $url '">' substr($url,0,$numchars) . '...</a>'
    If you don't want the "..."'s displayed when the string length is <= $numchars, just add some if logic using 'strlen($url)'.

    That's all there is to it.
    Curt Rebelein, Junior

  5. #5
    Senior Member R1Swedie is on a distinguished road
    Join Date
    Oct 2003
    Age
    28
    Posts
    118
    dammit! i've asked this question in like.. 3 different forums now and I keep getting misunderstod!

    I know that way of doing it, that is simple! But, what I want is...

    Let's say I have this piece of text in a $string:

    **************
    I rock, I'm better than you, therefore, visit
    http://www.isuck.com/sdf/sd/fsad/f/s...f/sdf/as/d.jpg so that you know where your home is.. yada yadyaydaydaydayd
    **************

    Now I want a script to pick up that URL ... and since it's so DAMN LONG, i want it shortened down to only 30 characters total and end it with "...". But of course only if it is larger than 30 characters.

    Get me now? I hope =)

    Thanks

  6. #6
    New Member Keith is on a distinguished road Keith's Avatar
    Join Date
    Feb 2001
    Posts
    4
    PHP Code:
    $url 'http://www.domain.tld/directory/file.ext';
    $numchars '30';
     
    if (
    strlen($url) > $numchars) echo '<a href="' $url '">' substr($url0$numchars) . '...</a>';
    else echo 
    '<a href="' $url '">' $url '</a>'
    like that?

  7. #7
    New Member digitok is on a distinguished road
    Join Date
    Apr 2003
    Location
    Perth, WA, Australia
    Age
    22
    Posts
    11
    vBulletin's URL shortener seems to work differently... It doesn't just do a simple "if it's more than 30 chars, truncate it and add ..." It adds the .'s in certain places in the string, then displays the end of the url... I don't know exactly how it's done...

    I'm sure it's simple logic... eg, if the string is more than 50 chars, display the first 35, then 3 dots, then the last 15, or something like that... (I counted and it displays 35, then 3 dots, then 15...) I'll make a small piece of code and post it here in a tick.

  8. #8
    New Member digitok is on a distinguished road
    Join Date
    Apr 2003
    Location
    Perth, WA, Australia
    Age
    22
    Posts
    11
    Okay, I coded it, and it's rather simple... Took less than 2 minutes
    PHP Code:
    <?
        $url 
    'someurl';

        if (
    strlen($url) > 50)
            echo 
    '<a href="',$url,'">',substr($url,0,35),'...',substr($url,-15),'</a>';

        else
            echo 
    '<a href="',$url,'">',$url,'</a>';
    ?>

+ Reply to Thread

Similar Threads

  1. Shortened links are a problem! Help!
    By Williamos in forum vBulletin 2 'How Do I' and Troubleshooting
    Replies: 4
    Last Post: Fri 19th Sep '03, 1:44pm
  2. Change Length Of Shortened URLs
    By adrianchew in forum vBulletin 2 'How Do I' and Troubleshooting
    Replies: 3
    Last Post: Sat 4th Jan '03, 2:05pm
  3. Writing the full URL of any URL typed into a post....
    By Gutspiller in forum vBulletin 2 'How Do I' and Troubleshooting
    Replies: 3
    Last Post: Tue 11th Sep '01, 6:59am
  4. [url] [/url] func test
    By norrin in forum A place to test things out
    Replies: 0
    Last Post: Fri 6th Oct '00, 5:00am

Bookmarks

Posting Permissions

Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts