SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Addict
    Join Date
    Jan 2005
    Location
    Paris
    Posts
    370
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    split methode with URL?

    Split URl Functions:

    I have long urls that i want to display on a table on multiple lines (don't ask me why, it just has to be done like that i have no say on that one lol), i would to write a javascript function that insert spaces into that url so when displaying a very long one, it could be broken between 2 or more lines...

    Original url: "http://www.website.com/dir1/dir2/dir4/thefile.html"
    My final string should be: "http://"http://www.website.com /dir1 /dir2 /dir4 /thefile.html

    i was thinking of using the split method to do this, but i am not sure it can be done that way...

    Anyone with hint?
    On a PHP/Java/XML/Javascript/MySQL internship right now!

  2. #2
    SitePoint Evangelist
    Join Date
    Jul 2007
    Posts
    345
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You could split on '//' first.
    Then split on '/'.
    Add the slashes back in before or during display of the pieces.

  3. #3
    SitePoint Addict
    Join Date
    Jan 2005
    Location
    Paris
    Posts
    370
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    like this?

    MyUrl=MyUrl.split('/').join(' /')
    Ok now this code has to actually insert a space every 20 characters
    On a PHP/Java/XML/Javascript/MySQL internship right now!

  4. #4
    SitePoint Evangelist
    Join Date
    Jul 2007
    Posts
    345
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    RegExp

    You might need a regular expressions guru to show you a superfast solution. I'm certainly not one of them.

    Yeh, I think the split, join hacking around will probably get it done

  5. #5
    SitePoint Addict
    Join Date
    Jan 2005
    Location
    Paris
    Posts
    370
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thank u
    On a PHP/Java/XML/Javascript/MySQL internship right now!

  6. #6
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

  7. #7
    SitePoint Addict
    Join Date
    Jan 2005
    Location
    Paris
    Posts
    370
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks for the link, i might try this too


    Object group(interval, str, ignoreWhiteSpace)
    function inserts a string every number of characters
    On a PHP/Java/XML/Javascript/MySQL internship right now!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •