Page 1 of 2 12 LastLast
Results 1 to 40 of 57

Thread: one preg_replace

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Posts
    259

    one preg_replace

    I need one perg_replace function to replace "\r\n" with "<br>" except "\r\n" that beetween [textarea] and [/textarea]

    is this impossible ?

  2. #2
    Lively Member scoutt's Avatar
    Join Date
    Aug 2002
    Posts
    84
    for you????? no, it is not possible
    Just Imagine what you can do with the power of php.

    257 Tutorials and counting.
    529 Snippets and growing.

    Add yours today @
    SnippetLibrary.com

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Posts
    259
    Originally posted by scoutt
    for you????? no, it is not possible
    M.R scoutt
    What about for others ?

  4. #4
    Lively Member scoutt's Avatar
    Join Date
    Aug 2002
    Posts
    84
    for others, they understand php
    your funny........
    Just Imagine what you can do with the power of php.

    257 Tutorials and counting.
    529 Snippets and growing.

    Add yours today @
    SnippetLibrary.com

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Posts
    259

    All

    All others understand it except me !!??!! I understand it also but I want to sure of my answer so help me to sure of that ..

  6. #6
    Fanatic Member cpradio's Avatar
    Join Date
    Apr 2002
    Posts
    616
    so why not post what you have and then allow us to help you from that?
    http://cpradio.net/
    Administrator @ WDForums and a Moderator @ WebXpertz City Forums

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Posts
    259

    All I have

    M.R cpradio.

    that is all I have

    $html = preg_replace("something here", "also something here", $html);

    I think that it's right code but the problem that i do not know this (something)

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Posts
    259

    I found that


  9. #9
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    I think you are confused on how you should go about solving your problem.

    Maybe if you provide us an example of how the text between the two <textarea></textarea> tags is being generated, we can find a solution for you.

    Unless you're doing something I haven't thought of, I'm pretty sure there's a way around using a preg_replace.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  10. #10
    Fanatic Member cpradio's Avatar
    Join Date
    Apr 2002
    Posts
    616
    also, I meant for you to show us what you have tested as your preg_replace expressions. We have given you plenty of examples in the past to where you should be getting the hang of this now.
    http://cpradio.net/
    Administrator @ WDForums and a Moderator @ WebXpertz City Forums

  11. #11

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Posts
    259

    clearing the problem

    the problem that I have text area that I insert some lines in it for exablem I write this lines inside this textarea and after that I press submit button:
    --------------------------------------
    that is a new php code
    open NotePad and write it
    [textarea]
    <?
    echo "A";
    echo "B";
    ?>
    [/textarea]
    ---------------------------------------

    I want to echo text that inside this textarea in another page so I replace new line with "<BR>" so and also replace [textarea] with <textarea> and [/textarea] with </textarea> because I want to display php code that I write above inside text area.

    when I do that I found output like that
    --------------------------------------------------
    that is a new php code
    open NotePad and write it

    and out put inside textarea like that
    ______________
    <? <BR>
    echo "A"; <BR>
    echo "B"; <BR>
    ?> <BR>
    ______________

    so the problem how can I get rid of <br> that inside this textarea.

    please help me to do that and that will be the last question in preg_replace function .. Thanks
    Last edited by prokhaled; Aug 11th, 2002 at 12:51 PM.

  12. #12
    Fanatic Member cpradio's Avatar
    Join Date
    Apr 2002
    Posts
    616
    I want to echo text that inside this textarea in another page so I replace new line with "<BR>"
    dont do that step
    http://cpradio.net/
    Administrator @ WDForums and a Moderator @ WebXpertz City Forums

  13. #13

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Posts
    259

    this step

    if I do not do this step this 2 lines:
    _____________________
    that is a new php code
    open NotePad and write it
    _____________________

    will become one line .. like that
    _________________________________________
    that is a new php code open NotePad and write it
    _________________________________________

  14. #14
    Fanatic Member cpradio's Avatar
    Join Date
    Apr 2002
    Posts
    616
    so use this as your echo:

    echo nl2br($text);

    That way you do not have to modify its contents
    http://cpradio.net/
    Administrator @ WDForums and a Moderator @ WebXpertz City Forums

  15. #15

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Posts
    259

    echo nl2br($text);

    When I used

    echo nl2br($text);

    also it give me the same result


    That it is the text inside textarea
    ______________
    <? <BR >
    echo "A"; <BR >
    echo "B"; <BR >
    ?> <BR >
    ______________

    to solve this problem I need replace_preg function to replace new line with "<br>" except new line that between [textarea] and [/textarea]

  16. #16
    Fanatic Member cpradio's Avatar
    Join Date
    Apr 2002
    Posts
    616
    NO!!

    You use that echo for when you need to print it to the page, you only use:

    PHP Code:
    echo $text
    when outputing in the <textarea>
    http://cpradio.net/
    Administrator @ WDForums and a Moderator @ WebXpertz City Forums

  17. #17

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Posts
    259

    Relly

    Relly that will not solve the problem. if you do not replace new line with <BR> all lines will show in on line .. if you replaced it the <br> will show inside textarea.

  18. #18
    Fanatic Member cpradio's Avatar
    Join Date
    Apr 2002
    Posts
    616
    a textarea reads \n\r as new lines. HTML does not! Try it and see for yourself
    http://cpradio.net/
    Administrator @ WDForums and a Moderator @ WebXpertz City Forums

  19. #19

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Posts
    259

    True

    a textarea reads \n\r as new lines. HTML does not! Try it and see for yourself.

    That is true. but when I replace \r\n with <br> the \r\n inside textarea changed to <BR>

  20. #20
    Fanatic Member cpradio's Avatar
    Join Date
    Apr 2002
    Posts
    616
    DONT REPLACE IT!!

    PHP Code:
    // To Screen
    echo nl2br($text);

    // To textarea
    echo "<textarea>$text</textarea>"
    http://cpradio.net/
    Administrator @ WDForums and a Moderator @ WebXpertz City Forums

  21. #21

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Posts
    259

    No

    I must replace it. the problem that I save text like that in database in one cell :
    ____________________
    that is a new php code
    open NotePad and write it
    [textarea]
    <?
    echo "A";
    echo "B";
    ?>
    [/textarea]
    ____________________

    so I want get it and replace \r\n with "<BR>"

    so my question . How replce \r\n with "<BR>" except any \r\n that between [textarea] and [/textarea]

  22. #22
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    prok...

    can you just post the section of code that you are doing this replacing in, and we'll make it work for you.

    maybe by actually seeing the code you'll understand what we mean?
    My evil laugh has a squeak in it.

    kristopherwilson.com

  23. #23
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256

    Re: No

    Originally posted by prokhaled
    I must replace it. the problem that I save text like that in database in one cell :
    ____________________
    that is a new php code
    open NotePad and write it
    [textarea]
    <?
    echo "A";
    echo "B";
    ?>
    [/textarea]
    ____________________

    so I want get it and replace \r\n with "<BR>"

    so my question . How replce \r\n with "<BR>" except any \r\n that between [textarea] and [/textarea]
    hmmm...is this all user typed?
    My evil laugh has a squeak in it.

    kristopherwilson.com

  24. #24
    Lively Member scoutt's Avatar
    Join Date
    Aug 2002
    Posts
    84
    boy you have lost me so much.

    what is going in the database? if you have a textarea and then you send the form, what OTHER text needs to be replaced? when the text from the textarea goes into the DB then don't replace the \r\n with anything.

    there is no other text. the form is sending only the textarea to DB.
    Last edited by scoutt; Aug 13th, 2002 at 01:48 PM.
    Just Imagine what you can do with the power of php.

    257 Tutorials and counting.
    529 Snippets and growing.

    Add yours today @
    SnippetLibrary.com

  25. #25
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    I don't understand preg_replaces very well, but I think it would be easier to replace all the \r\n with <br> then replace them within the [textarea] bits. Kinda seems odd. But maybe someone can help you with it.

    But now I understand why you can't just echo it seperately.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  26. #26
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Try working with this code that I posted in one of your previous threads. You should be able to modify it to work:

    PHP Code:
    <?php
        $test1 
    "Hi how Are you [E] A A A [/E] Fine A A [E] A any text A [/E]";
        echo 
    "Test1 = " $test1 "<br>After Function, = " convert($test1) . "<br><br>";
        
        
    //THE FUNCTION:
        
    function convert($text) {
            if (!
    strpos($text"[E]") === false) {
                do {
                    
    $pos strpos($text"[E]"$epos);
                    
    $ntext .= str_replace("A""B"substr($text$epos$pos $epos)); // . "<br>";
                    
                    
    $epos strpos($text"[/E]"$pos) + 4;
                    
    $ntext .= substr($text$pos$epos $pos);
                } while (!
    strpos($text"[E]"$epos) === false);
                
            } else {
                
    $ntext str_replace("A""B"$text);
            }        
            
            return 
    $ntext;
        }
    ?>
    My evil laugh has a squeak in it.

    kristopherwilson.com

  27. #27

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Posts
    259

    yes, please come again. I need your help

    M.R scoutt And M.R Hebo , that is the code that I use.

    Code:
    $SubjectText=$Row[SubjectText]
    $SubjectText = str_replace("
    Code:
    ", "<textarea  type=text name=ms rows=8 cols=70 wrap='virtual'>", $SubjectText);
    $SubjectText = str_replace("
    ", "</textarea>", $SubjectText); $SubjectText = str_replace("\r\n", " <BR> ",$SubjectText);

    I need some thing like [code] that use in forums to write code(s) but I want to disply this code inside textarea.

    Thanks.

    M.R Hobo. your code may work without problem but what I need to use short code. I think that preg_replace can do that but the problem that I do not know how can I use it.

  28. #28
    Lively Member scoutt's Avatar
    Join Date
    Aug 2002
    Posts
    84
    PHP Code:
    $SubjectText=$Row[SubjectText]
    $SubjectText str_replace("[CODE]""<textarea  type=text name=ms rows=8 cols=70 wrap='virtual'>"$SubjectText);
    $SubjectText str_replace("[/ CODE]""</textarea>"$SubjectText);
    $SubjectText str_replace("\r\n"" <BR> ",$SubjectText); 
    if that is all you are doing then take the

    $SubjectText = str_replace("\r\n", " <BR> ",$SubjectText);


    OUT!!!!! you don't need it.


    do it like this.....
    PHP Code:
    $SubjectText=$Row[SubjectText]
    $SubjectText str_replace("[CODE]""<textarea  type=text name=ms rows=8 cols=70 wrap='virtual'>"$SubjectText);
    $SubjectText str_replace("[/ CODE]""</textarea>"$SubjectText); 
    Just Imagine what you can do with the power of php.

    257 Tutorials and counting.
    529 Snippets and growing.

    Add yours today @
    SnippetLibrary.com

  29. #29

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Posts
    259

    the same problem

    I try you code but it give me the same problem. test it youself

    if $row[Subjecttext]= for exam:
    --------------------------------------
    that is a new php code
    open NotePad and write it
    [textarea]
    <?
    echo "A";
    echo "B";
    ?>
    [/textarea]
    ---------------------------------------

    I want to put "<br>" here only:
    that is a new php code <br> open NotePad and write it.

    but for sorry I found <br> writen with code inside textarea after replace \r\n with <br>

    for example I see that inside <textarea> after replacing.
    ___________________
    echo "A"; <br> echo "B";
    ___________________

  30. #30
    Lively Member scoutt's Avatar
    Join Date
    Aug 2002
    Posts
    84
    why do you keep saying open notepad? where are you getting this info from? where is

    that is a new php code
    open NotePad and write it
    [textarea]
    <?
    echo "A";
    echo "B";
    ?>
    [/textarea]


    coming from????
    Just Imagine what you can do with the power of php.

    257 Tutorials and counting.
    529 Snippets and growing.

    Add yours today @
    SnippetLibrary.com

  31. #31

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Posts
    259

    I do not understand

    I do not understand .. that is for example.

  32. #32
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Originally posted by scoutt
    why do you keep saying open notepad? where are you getting this info from? where is

    that is a new php code
    open NotePad and write it
    [textarea]
    <?
    echo "A";
    echo "B";
    ?>
    [/textarea]


    coming from????
    from a database, I believe?
    My evil laugh has a squeak in it.

    kristopherwilson.com

  33. #33
    Lively Member scoutt's Avatar
    Join Date
    Aug 2002
    Posts
    84
    that is what I am thinking. if it is from a database then when you insert that into the database don't replace the \r\n with <br>'s duh.

    for an example means you don't know what the heck you are doing as you are just asking for code. well for an example pay attention to what we say and you might get farther.
    Just Imagine what you can do with the power of php.

    257 Tutorials and counting.
    529 Snippets and growing.

    Add yours today @
    SnippetLibrary.com

  34. #34
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Originally posted by scoutt
    that is what I am thinking. if it is from a database then when you insert that into the database don't replace the \r\n with <br>'s duh.

    for an example means you don't know what the heck you are doing as you are just asking for code. well for an example pay attention to what we say and you might get farther.
    chill out

    Although I'm not sure, I think the database entries could be user input. If so, then he has no control over it.

    Keep your thumb out of your ass, scoutt.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  35. #35
    Lively Member scoutt's Avatar
    Join Date
    Aug 2002
    Posts
    84
    up yours Hobo
    Just Imagine what you can do with the power of php.

    257 Tutorials and counting.
    529 Snippets and growing.

    Add yours today @
    SnippetLibrary.com

  36. #36

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Posts
    259

    yes

    _________________________
    that is a new php code
    open NotePad and write it
    [textarea]
    <?
    echo "A";
    echo "B";
    ?>
    [/textarea]
    _________________________

    yes, this text come from database.

  37. #37
    Lively Member scoutt's Avatar
    Join Date
    Aug 2002
    Posts
    84
    how is it going into the DB
    Just Imagine what you can do with the power of php.

    257 Tutorials and counting.
    529 Snippets and growing.

    Add yours today @
    SnippetLibrary.com

  38. #38

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Posts
    259

    any user

    by any user.

    any user can add subject like that . there is form contain textarea and submit button, and any user can add subject to database like this this forum.

  39. #39
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256

    Re: yes, please come again. I need your help

    Originally posted by prokhaled
    M.R Hobo. your code may work without problem but what I need to use short code. I think that preg_replace can do that but the problem that I do not know how can I use it.
    That's great...so why don't you write it then? I'm not going to write 42 solutions for you so you can pick the one you like the best.

    Originally posted by scoutt
    up yours Hobo
    I don't swing that way, man.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  40. #40
    Lively Member scoutt's Avatar
    Join Date
    Aug 2002
    Posts
    84

    Re: any user

    Originally posted by prokhaled
    by any user.

    any user can add subject like that . there is form contain textarea and submit button, and any user can add subject to database like this this forum.
    then if you are entring it in the DB don't do a str_replace. just enter the textarea contents in the DB just like it sits.
    Just Imagine what you can do with the power of php.

    257 Tutorials and counting.
    529 Snippets and growing.

    Add yours today @
    SnippetLibrary.com

Page 1 of 2 12 LastLast

Posting Permissions

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



Click Here to Expand Forum to Full Width