Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder tylerjca's Avatar
    Join Date
    Dec 2002
    Location
    Canada
    Posts
    162
    Thanks
    1
    Thanked 0 Times in 0 Posts

    extract \n between code then replace remaining \n with <br>

    Hi. What i'm trying to do is take out any \n (line break) from between certain tags such as <style> and </style> and then after that, replace all the remaining \n with <br>

    so far all i know how to do is the <br>
    PHP Code:
    <?php
    $my_string 
    "<style>
    body{
        color:#00f;
        background-color:#000;
        }
    </style>

    Then this is the
    rest of the
    string with
    random
    line breaks"
    ;

    $text preg_replace("(\r\n|\r\n)","<br />",$my_string);
    ?>
    The problem with this is that the <style> tag doesn't do what it should because the script puts <br /> where they should not be

    So how would I make it so the \n between <style> and </style> are replaced with just " " (just as an example)

    Thanks in advance

  • #2
    New Coder
    Join Date
    Jan 2006
    Posts
    53
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hmm.. you could do something like this:

    PHP Code:
    <?php
    $my_string 
    "<style>
    body{
        color:#00f;
        background-color:#000;
        }
    </style>

    Then this is the
    rest of the
    string with
    random
    line breaks"


    $var1 explode("</style>"$my_string);
    $text1 preg_replace("(\r\n|\r\n)","",$var1[0]); 
    $text2 nl2br($var1[1]);
    $my_string $text1."</style>".$text2;
    ?>

    It might and might not work... It's just an idea, I haven't tested this code.


  •  

    Posting Permissions

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