Page 4 of 6 FirstFirst ... 23456 LastLast
Results 31 to 40 of 57

Thread: How to restore broken lines in links in my PHP editor?

  1. #31
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    If it's relying on new lines for paragraphs, then would it also have <a> tags for links? Wouldn't it be one or the other?
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  2. #32
    Join Date
    May 2012
    Location
    Hitchhiking the Galaxy
    Posts
    1,013
    Thanks
    46
    Thanked 139 Times in 139 Posts
    Blog Entries
    1

    Default

    "Most good programmers do programming not because they expect to get paid or get adulation by the public, but because it is fun to program." - Linus Torvalds
    Anime Views Forums
    Bernie

  3. #33
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    Quote Originally Posted by djr33 View Post
    If it's relying on new lines for paragraphs, then would it also have <a> tags for links? Wouldn't it be one or the other?
    Markdown generally allows HTML. Specific implementations may differ.

    Quote Originally Posted by bernie1227 View Post
    http://jsfiddle.net/traq/vG3U6/

  4. #34
    Join Date
    May 2012
    Location
    Hitchhiking the Galaxy
    Posts
    1,013
    Thanks
    46
    Thanked 139 Times in 139 Posts
    Blog Entries
    1

    Default

    You really didn't need a jsfiddle to ask me that traq:
    (text.split("<").length - 1) tells us how many opening tags if you want to know how many there are.
    "Most good programmers do programming not because they expect to get paid or get adulation by the public, but because it is fun to program." - Linus Torvalds
    Anime Views Forums
    Bernie

  5. #35
    Join Date
    Oct 2012
    Posts
    180
    Thanks
    22
    Thanked 1 Time in 1 Post

    Default

    I don't know if I can nudge some of you in the right direction but is there something that can go like this?

    Code:
    text = text.replace('/<([^<>]+)>/g','"<" ...... ">"');
    Where the dots are we need to tell that only new lines between the tags must be stripped...

    Or am I totally off?

  6. #36
    Join Date
    May 2012
    Location
    Hitchhiking the Galaxy
    Posts
    1,013
    Thanks
    46
    Thanked 139 Times in 139 Posts
    Blog Entries
    1

    Default

    You could have a try with something along the lines of:
    Code:
    text.replace(/(<\S+)\n*(\S+>)/g, "$1$2");
    "Most good programmers do programming not because they expect to get paid or get adulation by the public, but because it is fun to program." - Linus Torvalds
    Anime Views Forums
    Bernie

  7. #37
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    http://jsfiddle.net/traq/kRsND/

    Actually didn't end up using a look-ahead (my idea required a look-behind also, which javascript apparently doesn't implement ).

    I could only get it to work by putting it in a loop, though. I'm not sure why the g modifier isn't having the effect I expect (probably, I misunderstand what regex means by "global"). Removing it has no effect on the result.

    for reference, here's the regex I'm using:
    Code:
    /(<[^>]*)\n+([^>]*>)/g
    
    // explanation:
    
    (         // start $1
       <      // opening bracket
       [^>]*  // anything not a closing bracket
    )         // end first match
    \n+       // one or more newlines
    (         // start $2
       [^>]*  // anything not a closing bracket
       >      // closing bracket
    )         // end $2
    
    // then I just replaced the *whole* match with only $1 and $2.
    Edit:
    Quote Originally Posted by bernie1227 View Post
    You could have a try with something along the lines of:
    Code:
    text.replace(/(<\S+)\n*(\S+>)/g, "$1$2");
    ...beat by 3 minutes.

  8. #38
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    fixed. http://jsfiddle.net/traq/kRsND/

    Code:
    var regex = /(<[^>\n]*)\s+([^>\n]*>)/g;
    /*
    
    (           // start $1
       <        // opening bracket
       [^>\n]*  // anything not a closing bracket *or* a newline
    )           // end $1
    \s+         // one or more *whitespace* (including newlines)
    (           // start $2
       [^>\n]*  // anything not a closing bracket *or* a newline
       >        // closing bracket
    )           // end $2
    
    */
    
    text = text.replace( regex,'$1 $2' );
    // note the single non-breaking space between $1 and $2

  9. The Following User Says Thank You to traq For This Useful Post:

    qwikad.com (12-21-2012)

  10. #39
    Join Date
    Oct 2012
    Posts
    180
    Thanks
    22
    Thanked 1 Time in 1 Post

    Default

    This has fixed it. Wow. Thanks!

    I will still need to test it to find out whether or not it works with all sorts of HTML banner ads / HTML codes without messing something up, but as of now it works perfect.


    Quote Originally Posted by traq View Post
    fixed. http://jsfiddle.net/traq/kRsND/

    Code:
    var regex = /(<[^>\n]*)\s+([^>\n]*>)/g;
    /*
    
    (           // start $1
       <        // opening bracket
       [^>\n]*  // anything not a closing bracket *or* a newline
    )           // end $1
    \s+         // one or more *whitespace* (including newlines)
    (           // start $2
       [^>\n]*  // anything not a closing bracket *or* a newline
       >        // closing bracket
    )           // end $2
    
    */
    
    text = text.replace( regex,'$1 $2' );
    // note the single non-breaking space between $1 and $2

  11. #40
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    glad we could help.

    once you've completed your testing,

    If your question has been answered, please mark your thread "resolved":
    • On your original post (post #1), click [edit], then click [go advanced].
    • In the "thread prefix" box, select "Resolved".
    • Click [save changes].

Similar Threads

  1. How to create a broken links checker from scratch
    By SR123 in forum Looking for such a script or service
    Replies: 0
    Last Post: 06-03-2009, 03:03 PM
  2. Restore slide position!!!
    By shlajfka in forum Dynamic Drive scripts help
    Replies: 1
    Last Post: 11-25-2008, 01:04 PM
  3. links at the center appear broken
    By leonidassavvides in forum HTML
    Replies: 1
    Last Post: 04-23-2008, 02:49 PM
  4. Program to check broken links?
    By Freeman in forum The lounge
    Replies: 6
    Last Post: 08-24-2007, 04:04 PM
  5. Code Restore... (need help)
    By Harlem Of Nem in forum JavaScript
    Replies: 5
    Last Post: 08-06-2007, 08:03 AM

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
  •