Re: Splitting up long URLs

From: Date: Mon, 07 Jul 2008 15:57:07 +0000
Subject: Re: Splitting up long URLs
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-276374@lists.php.net to get a copy of this message
On Tue, Jul 1, 2008 at 4:26 PM, Brian Dunning <brian@briandunning.com> 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.

« previous php.general (#276374) next »