Re: Splitting up long URLs

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

 



On Tue, 2008-07-01 at 13:26 -0700, Brian Dunning 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?
> 
> If there's a CSS solution that's better than a PHP solution I'll take  
> that too.   :-)
> 

For URLs you can do a tinyurl-type solution. Quite easy in fact. Just
save the long url in a db table, along with a short url (say a
4-character random string). Then do a page that looks up the short url
and redirects to a long url (eg. http://www.myblog.com/r?id=Sve7
redirects to http://www.veryverylongurl.com/blahblahblah.php). For extra
points you can make the short url look like http://tiny.myblog.com/Sve7.
Just remember to put the short url creation in a loop that checks that
the short url isn't in the DB already and repeat if it is.

For long words, you could explode the words into an array, and if the
words are longer than a certain length, insert a hyphen and space for
your wrap. Then just implode back into your string and bob's your uncle.

Anyhow that's how I'd do it.

J


-- 
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