Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Apr 2008
    Posts
    26
    Thanks
    6
    Thanked 0 Times in 0 Posts

    How IPB Shortens URL's

    I was curious to find out how IPB takes a long URL such as:

    Code:
    http://www.google.com/search?hl=en&client=firefox-a&channel=s&rls=org.mozilla%3Aen-US%3Aofficial&hs=BCR&q=metacafe&btnG=Search
    and turns it into

    Code:
    http://www.google.com/search?hl=en&cli...amp;btnG=Search
    with the three ... in the middle instead of the whole long URL. Does anyone know how?

    Thanks.

    EDIT:

    Now that I look at it, Vbulletin does the same thing:

    http://www.google.com/search?hl=en&c...fe&btnG=Search
    Last edited by pixencom; 05-14-2008 at 09:10 AM.
    Atlanta Web Design <- They do good work.

  • #2
    Regular Coder GO ILLINI's Avatar
    Join Date
    Jun 2005
    Location
    USA
    Posts
    634
    Thanks
    0
    Thanked 7 Times in 7 Posts
    Its fairly simple actaully
    step
    1) if url var is less then x chars do nothing or
    2) get first 15(?) chars into a variable.
    3) get the last 10 chars
    4) $first15 ... $last10 (inside a link to $orig_url)

    Im sure that A) you can find a class, function that will do this for you already B) you can write it on your own(as its not very hard) or C) ask someone here to write it for you

    Hope this leads you in the right direction,
    -Adam
    Why not thank me?

    http://adamsworld.name

  • #3
    New Coder
    Join Date
    Apr 2008
    Posts
    26
    Thanks
    6
    Thanked 0 Times in 0 Posts
    Thanks for your reply. Here is the function I made. This function shortens the url to 45 characters plus 7 characters for the divider.

    Code:
    <?php
    function shortenurl($url){
    	$length = strlen($url);
    	if($length > 45){
    		$length = $length - 30;
    		$first = substr($url, 0, -$length);
    		$last = substr($url, -15);
    		$newurl = $first."[ ... ]".$last;
    		return $newurl;
    	}else{
    		return $url;
    	}
    }
    
    $longurl = "http://www.google.com/search?hl=en&client=firefox-a&channel=s&rls=org.mozilla%3Aen-US%3Aofficial&hs=BCR&q=metacafe&btnG=Search";
    $shorturl = shortenurl($longurl);
    echo"<a href=\"$longurl\">$shorturl</a>";
    ?>
    Last edited by pixencom; 05-14-2008 at 09:10 AM.
    Atlanta Web Design <- They do good work.


  •  

    Posting Permissions

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