I'm working on a page that shows links from a database.. Some of the links are really long so I want to break them up with some " ... " in the link to make it display a shorter link... For example, I'd want http://forums.digitalpoint.com/newthread.php?do=newthread&f=37 displayed something like http://forums.digitalpoint.com/n...ad&f=37 Know how I can do this?
you can probably use mod_rewrite to change them to whatever you want. But I'm sorry, I don't know the exact code needed. A user here called Nintendo is really good with that type of stuff. Try posting again with a mod_rewrite thread and see if you can get someone to tell you how to do it exactly. This assumes you are on a unix server of course.
That's cool. Mod_rewrite is great if you can learn it or get someone to help. http://httpd.apache.org/docs/1.3/mod/mod_rewrite.html Good luck.
<?php $url = "http://forums.digitalpoint.com/newthread.php?do=newthread&f=37"; $hyperlink = "<a href=\"$url\">$url</a>"; function shrink_url( $link, $limit = 40, $dots = 5 ) { return sprintf('%s%s%s', substr( $link, 0, $limit ), str_pad('.', $dots, '.' ), substr( $link, strlen( $link ) - 4 ) ); } function format_hyperlink( $hyperlink ) { if(!preg_match('~(>(.*?[^<])<)~', $hyperlink, $url )): return false; elseif( $url[1] ): return str_replace( $url[1], shrink_url( $url[1] ), $hyperlink ); endif; } echo "Shrunk Url<br />\r\n"; echo shrink_url( $url ) . "\r\n"; echo "Shrunk hyperlink<br/>\r\n"; echo format_hyperlink( $hyperlink ) . "\r\n"; PHP:
krakjoe, that code is working great. One issue I'm having though. It does it to a URL that is real short too though. How can I only get it to truncate the URL if it's over 40 characters? For example, the link http://wiifamily.net is shown as http://wiifamily.net...ly.net instead. Just so you know, I modified $dots = 5 to $dots = 3 and $link, strlen( $link ) - 4 to $link, strlen( $link ) - 6. Awaiting your response. Thanks again so far!!
Fixed it. Issue resolved. Rep given to krakjoe. Thanks!! Finished product can be seen at http://nuurl.us/stats.php.