Page 5 of 6 FirstFirst ... 3456 LastLast
Results 41 to 50 of 57

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

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

    Default

    qwikad, it's perfectly okay to post your question here. It's on the same topic, after all, and it's your thread. Let me know if you want me to un-resolve the thread and restore your post.

    *****

    So, your problem is that the regex matches when newlines separate the tag into two parts, but not more than two, correct?
    Code:
    works:
    <tag
    one>
    
    works:
    <tag
    
    
    two>
    
    breaks:
    <tag
    three
    breaks>
    new fiddle

    I have to admit, the only thing that occurs to me is adding additional, optional subpatterns in the middle of the regex.
    This is not a solution, obviously, since you'll always be subject to a maximum of however many subpatterns you add.

    I'll think about it. Anyone else have ideas?

  2. #42
    Join Date
    Oct 2012
    Posts
    180
    Thanks
    22
    Thanked 1 Time in 1 Post

    Default

    No, it's a bit different (unless I misunderstood you).

    This works:

    Code:
    <img src="http://qwikad.com/images/logo.png" 
    alt="something" title="something">
    This also works:

    Code:
    <img src="http://qwikad.com/images/logo.png" 
    
    alt="something" title="something">
    This, however doesn't:

    Code:
    <img src="http://qwikad.com/images/logo.png" 
    alt="something" 
    title="something">

    Neither does this:

    Code:
    <img src="http://qwikad.com/images/logo.png" 
    
    alt="something" 
    
    title="something">


    Hope it helps.

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

    Default

    no, that's exactly what I meant.

    I know this can be done, but it's evading me right now.
    I'm also a little preoccupied with some other stuff, so it's a bit hard to really get into it, but I'll keep the problem in mind.

  4. #44
    Join Date
    Oct 2012
    Posts
    180
    Thanks
    22
    Thanked 1 Time in 1 Post

    Default

    Sounds fair, no rush. I'll be stopping by here from time to time to see if you had a chance to look at it again.

  5. #45
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    2,385
    Thanks
    100
    Thanked 113 Times in 111 Posts

    Default

    This looks like a javascript problem. I do have a fair amount of experience with PCRE (Perl Compatible Regular Expressions) though it has been a while for me. I have a fair collection of PCRE scripts and found one that looked similar to what is being worked on here. Can you reverse engineer it to to suit your needs?

    Code:
    <?php
    $text="<img src=\"http://qwikad.com/images/logo.png\" 
    
    alt=\"something\"
    
    title=\"something\">this
    is
    
    fine
    <img src=\"http://qwikad.com/images/logo.png\" 
    
    alt=\"something\"
    
    title=\"something\">";
    $text=preg_replace('/(\r\n){1,}(?=((?!<).)*>)/s','XX',$text);
    echo "$text";
    ?>
    I really need several more examples so that I can see exactly what it is you are trying to do though. In short I am looking for a newline and as long as it is not followed by an opening tag (which indicates that it is a newline located within a tag) it will replace it with XX. The s modifier is set so that the dot will also recognize newlines.

    Even though I wrote the above PCRE it has been a long enough time since I have worked with it that it is rather hazy for me. If PCRE does not help at all I will quietly bow out .

    Later
    To choose the lesser of two evils is still to choose evil. My personal site

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

    Default

    Very helpful. Had to change it a bit to work in javascript (what's the s flag do? it's not supported in js) -
    Code:
    /(\s)+(?=((?!<).)*>)/g
    This does what we need, but only one-at-a-time: i.e., you have to run it twice if there are two line breaks in a tag, three times if there are three, etc..

  7. #47
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    2,385
    Thanks
    100
    Thanked 113 Times in 111 Posts

    Default

    That's why you need the s modifier. s alters the . so that it recognizes newlines as well as other characters otherwise it stops once it gets to a newline, which in our situation is bad. You can read up more on the s modifier as well as most (not all) of the other modifiers here.
    To choose the lesser of two evils is still to choose evil. My personal site

  8. #48
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    2,385
    Thanks
    100
    Thanked 113 Times in 111 Posts

    Default

    The equivalent of . with the s modifier would be [\s\S].

    A reference that shows how javascript regular expressions is different from perl regular expressions is http://www.regular-expressions.info/javascript.html

    It is very short, but also has several workarounds.
    Last edited by james438; 01-10-2013 at 06:50 AM.
    To choose the lesser of two evils is still to choose evil. My personal site

  9. #49
    Join Date
    Oct 2012
    Posts
    180
    Thanks
    22
    Thanked 1 Time in 1 Post

    Default

    james438,

    This is what was offered by traq. And it works well for one broken line:

    Code:
    var regex = /(<[^>\n]*)\s+([^>\n]*>)/g;
    text = text.replace( regex,'$1 $2' );
    I was thinking how many broken lines can an average HTML banner ad possibly have and still be a valid code, and I came up with 8:

    Code:
    <
    img 
    src="http://something.com/images/something.png" 
    title="something" 
    alt="something" 
    width="300" 
    height="250" 
    border="0"
    >
    So if that var regex could be adjusted to restoring 8 broken lines, I think it will cover every possible inconsistency of any HTML banner ad (and more).

  10. #50
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    2,385
    Thanks
    100
    Thanked 113 Times in 111 Posts

    Default

    Can I see an example of the javascript that uses regular expressions so that I can work on it to get it to work? The php code works just fine on my end, but I am less familiar with javascript's version of regular expressions which is probably the most limited of all the web coding languages with Perl easily being the best. Still there are enough similarities that I can probably work with it, but it would be helpful to see the sample code you are working with.

    What you just posted quickad.com is actually rather easier to work with. The following is trickier because the PCRE needs to know when to replace newlines and when not to.

    Code:
    <img src="http://qwikad.com/images/logo.png" 
    
    alt="something"
    
    title="something">this
    is
    
    fine
    <img src="http://qwikad.com/images/logo.png" 
    
    alt="something"
    
    title="something">
    Does this have to be in javascript or can php work? It should be fine either way though.
    To choose the lesser of two evils is still to choose evil. My personal site

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
  •