|
View:
New views
14 Messages
—
Rating Filter:
Alert me
|
|
|
Splitting up long URLsI 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. :-) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php |
|
|
Re: Splitting up long URLsOn 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. :-) You need to manually chop them. The wordwrap() function should be able to do it for you. Although, you'll have issues with HTML if I recall correctly. CSS will not do it for you unless you want to have overflow and either hide the overflow or have scrollbars appear. Cheers, Rob. -- http://www.interjinn.com Application and Templating Framework for PHP -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php |
|
|
RE: Splitting up long URLs> -----Original Message-----
> From: Brian Dunning [mailto:brian@...] > Sent: Tuesday, July 01, 2008 3:27 PM > To: php-general@... > Subject: [PHP] Splitting up long URLs > > 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. :-) STFW: http://www.w3.org/TR/css3-text/#white-space ...doesn't say much in the article about whether or not it will break up "words" rather than lines, but it's worth a shot. Todd Boyd Web Programmer -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php |
|
|
Re: Splitting up long URLsIf you want to do it on the php side, I would do something like this:
<a href="$fullURL">substr($fullURL, 0, 9)."..."</a> It would provide a valid link using the full url, but chop off everything after the 10th character and replace with a "...". Nate On Tue, Jul 1, 2008 at 3:45 PM, Boyd, Todd M. <tmboyd1@...> wrote: > > -----Original Message----- > > From: Brian Dunning [mailto:brian@...] > > Sent: Tuesday, July 01, 2008 3:27 PM > > To: php-general@... > > Subject: [PHP] Splitting up long URLs > > > > 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. :-) > > STFW: http://www.w3.org/TR/css3-text/#white-space > > ...doesn't say much in the article about whether or not it will break up > "words" rather than lines, but it's worth a shot. > > > Todd Boyd > Web Programmer > > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > |
|
|
Re: Splitting up long URLsOn 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 |
|
|
Re: Splitting up long URLsOn Wed, 2008-07-02 at 08:23 +0200, Jason Norwood-Young wrote:
> For URLs you can do a tinyurl-type solution. Dur, just realised it's only *display* that you're worried about so shortening the url isn't really an issue. It's too early in the morning... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php |
|
|
Re: Splitting up long URLsOn Jul 1, 2008, at 4:27 PM, Nate Tallman wrote:
> If you want to do it on the php side, I would do something like this: > > <a href="$fullURL">substr($fullURL, 0, 9)."..."</a> > > It would provide a valid link using the full url, but chop off > everything > after the 10th character and replace with a "...". > > Nate I've seen some sites(/browsers?) do something similar to this - they show the first of the URL and some of the last. For example... <?php $url = "http://www.letshaveareallylongurl.com/somedirectory/". "somelocation/someplace/32j1580/ksaladfji/". "dji23adf/adfjadf/dja9Jkda.html"; $len = strlen ($url); $shortLen = 40; $longLen = 100; if ($len > ($shortLen + 10)) { if ($len > $longLen) { // Show first and last of the url $newUrl = substr ($url, 0, $shortLen) . '...' . substr ($url, -10); } else { // Only show first $newUrl = substr ($url, 0, $shortLen+7) . '...'; } } else { $newUrl = $url; } echo "<a href=\"$url\">$newUrl</a>"; ?> This output would be: http://www.letshaveareallylongurl.com/so...9Jkda.html Of course, you can change the lengths around to suit your needs. Just another way to skin the cat. ~Philip > On Tue, Jul 1, 2008 at 3:45 PM, Boyd, Todd M. <tmboyd1@...> > wrote: > >>> -----Original Message----- >>> From: Brian Dunning [mailto:brian@...] >>> Sent: Tuesday, July 01, 2008 3:27 PM >>> To: php-general@... >>> Subject: [PHP] Splitting up long URLs >>> >>> 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. :-) >> >> STFW: http://www.w3.org/TR/css3-text/#white-space >> >> ...doesn't say much in the article about whether or not it will >> break up >> "words" rather than lines, but it's worth a shot. >> >> >> Todd Boyd >> Web Programmer -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php |
|
|
Re: Splitting up long URLsOn Tue, Jul 1, 2008 at 4:26 PM, Brian Dunning <brian@...> 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 |
|
|
Re: Splitting up long URLsAt 11:57 AM -0400 7/7/08, Daniel Brown wrote:
> 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"; >?> > Very nice. However, there isn't a way to change what the user see's in the browser's url box, is there? For example, can you send a user to http://example.com/a.php, but they see http://example.com/b.php in their browser? Cheers, tedd -- ------- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php |
|
|
|
|
|
|
|
|
Re: Splitting up long URLsAt 12:05 PM -0400 7/8/08, Andrew Ballard wrote:
> > However, there isn't a way to change what the user see's in the browser's >> url box, is there? >> >> For example, can you send a user to http://example.com/a.php, but they see >> http://example.com/b.php in their browser? >> >> Cheers, >> >> tedd > >Sounds pretty phishy to me, tedd. :-) > >Andrew Andrew: Yes, but there's nothing wrong with learning -- it's like talking to other women while you're married, it's what you do with the information that makes it right or wrong. Cheers, tedd -- ------- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php |
|
|
Re: Splitting up long URLsOn Tue, 2008-07-08 at 12:42 -0400, tedd wrote:
> At 12:05 PM -0400 7/8/08, Andrew Ballard wrote: > > > However, there isn't a way to change what the user see's in the browser's > >> url box, is there? > >> > >> For example, can you send a user to http://example.com/a.php, but they see > >> http://example.com/b.php in their browser? > >> > >> Cheers, > >> > >> tedd > > > >Sounds pretty phishy to me, tedd. :-) > > > >Andrew > > Andrew: > > Yes, but there's nothing wrong with learning -- it's like talking to > other women while you're married, it's what you do with the > information that makes it right or wrong. That reminds me of something I heard on TV a long time ago... Just because I've ordered doesn't mean I can't keep looking at the menu. :) Personally, me and the missus have more fun teasing each other when we find the other's eyes wandering. Cheers, Rob. -- http://www.interjinn.com Application and Templating Framework for PHP -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php |
|
|
Re: Splitting up long URLsAt 2:07 PM -0400 7/8/08, Robert Cummings wrote:
>On Tue, 2008-07-08 at 12:42 -0400, tedd wrote: > > At 12:05 PM -0400 7/8/08, Andrew Ballard wrote: > > >Sounds pretty phishy to me, tedd. :-) >> > >> >Andrew >> >> Andrew: >> >> Yes, but there's nothing wrong with learning -- it's like talking to >> other women while you're married, it's what you do with the >> information that makes it right or wrong. > >That reminds me of something I heard on TV a long time ago... > > Just because I've ordered doesn't mean I can't keep looking at > the menu. > >:) I heard it: "Just because I'm on a diet doesn't mean I can't look at the menu." I also like: "I gave sex up for food and now I can't even get into my own pants." Cheers, tedd -- ------- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php |
| Free Forum Powered by Nabble | Forum Help |