Regex character for "NOT LIKE"

Discussion in 'PHP' started by mnaghdi, Nov 13, 2009.

  1. #1
    Hi

    What is the character for "NOT LIKE" in regex?

    My problem is that when I retrieve data from mysql I'll have to replace all linebreaks with "<br/>" but it also adds line breaks on please that it shouldn't for example here:
    
    <table>
    <br/><tr>
    <br/><td>
    <br/>....
    
    PHP:
    So either somebody here helps me with an all-occasions solution or I'll have to specify the exact places where "<br/>" shouldn't be added.

    this works and adds an "<br/>" to every linebreak:
    $value = preg_replace("/\r/", "<br/>", $value);
    I tried this but it didn't work:
    $value = preg_replace("/\r!(>\r)/", "<br/>", $value);
     
    mnaghdi, Nov 13, 2009 IP
  2. mastermunj

    mastermunj Well-Known Member

    Messages:
    687
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    110
    #2
    why not use nl2br()?
     
    mastermunj, Nov 13, 2009 IP
  3. mnaghdi

    mnaghdi Peon

    Messages:
    48
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Much neater but still adds "<br/>"s to the places it shouldn't like "</td><br/><td>"
     
    mnaghdi, Nov 13, 2009 IP
  4. szalinski

    szalinski Peon

    Messages:
    341
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #4
    first, let's clear something up. a '<br/>' tag IS a linebreak. '\r\n' however is a carriage return (or CRLF, or new line).

    if your mysql data has '\r\n' repeatedly in it, and you intend to show output this in a browser, you don't need to worry, as even though the sourcecode will reflect the newlines, they won't appear in the final parsed html output (in your browser window). so why exactly is it you need to do this - are you trying to clean up the source code output?

    anyway if you must, you could try (untested)
    $value = preg_replace("/[^>\r]\n?/", "<br/>", $value);
    PHP:
    either way you get the idea that you negate character classes with [^<characters here>].
     
    szalinski, Nov 20, 2009 IP