Re: Splitting up long URLs

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Jul 1, 2008 at 4:26 PM, Brian Dunning <brian@xxxxxxxxxxxxxxxx> wrote:
> I have a web page that lists "most recent comments" in a left margin.
> Sometimes people post long URLs, or even just really really long words, that
> force that margin to display way too wide, screwing up the page layout. Is
> there a way to make sure URLs or other text in a string gets split up so
> this doesn't happen?

    You could display the URL's the way Google handles them:

<?php

function shortenURL($longURL) {
        preg_match('/\/?[a-z0-9\.\-]+\//Ui',$longURL,$matches);
        $shortURL = str_replace('/','',$matches[0]);
        return $shortURL;
}

$longURL = "http://some-SPAM-URL-011.example.com/v14gra/p3n15_pump.php?affil=43ERG3245wert002934&boo=yaa!";;

echo "<a href=\"".$longURL."\">".shortenURL($longURL)."</a><br />\n";
?>

-- 
</Daniel P. Brown>
Dedicated Servers - Intel 2.4GHz w/2TB bandwidth/mo. starting at just
$59.99/mo. with no contract!
Dedicated servers, VPS, and hosting from $2.50/mo.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux