Forum Moderators: coopster

Message Too Old, No Replies

Adding space to URL

To make long URLs wrap round

         

WebWalla

8:02 am on Nov 7, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi,

I have a beginner's programming knowledge and I'm trying to adapt a script to work with my site, so I wonder if any of you could help.

My script displays URLs of other sites, and I'm seeing that very long URLs don't wrap within the table, therefore pushing out the borders and spoiling the format.

Can anybody give me a piece of code that will take an URL variable (e.g. $url) and parse it to place a space after the 1st forward slash
(e.g. http://www.example.com/very/long/url/ would be replaced by http://www.example.com/ very/long/url/)

Alternatively, the space could be placed after the second slash, so that not so many URLs are changed this way.
(e.g. http://www.example.com/very/long/url/ would be replaced by http://www.example.com/very/ long/url/)

Many thanks for any indicators you can give me.

barns101

11:40 am on Nov 7, 2006 (gmt 0)

10+ Year Member



Take a look at the explode [php.net] function. You can then use the forward slash to split the URL into different parts and display them as you wish.

eelixduppy

12:00 pm on Nov 7, 2006 (gmt 0)



You can always just limit the length of the url too. Something like this:

if(strlen($link) > 20) {
echo substr($link,0,20).'...';
} else {
echo $link;
}

Good luck!

WebWalla

3:46 pm on Nov 9, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Quick post just to say thanks. Finally used the second solution - it fits in better with my site.

Thanks!