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 7 of 7
  1. #1
    me'
    me' is offline
    Senior Coder
    Join Date
    Nov 2002
    Location
    Warwickshire, England
    Posts
    1,229
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Matching double line breaks

    I'm trying to double line breaks in a user-entered field into XML. I've tried matching them with a simple regexp:
    Code:
    '<paragraph>' . preg_replace('/^^/m', "</paragraph>\n\n<paragraph>", $_POST['post']); . '</paragraph>'
    This does seem to be matching the paragraphs, but it goes over the top. For example,
    hello

    world
    Gives
    Code:
    <paragraph></paragraph>
    
    <paragraph>hello
    
    </paragraph>
    
    <paragraph>
    
    </paragraph>
    
    <paragraph>world</paragraph>
    Any insight/solutions?
    David House - Perfect is achieved, not when there is nothing left to add, but when there is nothing left to take away. (Antoine de St. Exupery).
    W3Schools | XHTML Validator | CSS Validator | Colours | Typography | HTML&CSS FAQ | Go get Mozilla Now | I blog!

  • #2
    me'
    me' is offline
    Senior Coder
    Join Date
    Nov 2002
    Location
    Warwickshire, England
    Posts
    1,229
    Thanks
    0
    Thanked 0 Times in 0 Posts
    All right, no-one seems to have a clue. Perhaps relevant: I'm using Windows which uses [lf][cr] to mark new lines, compared to unix where simply [lf] is used. Could this be why?
    David House - Perfect is achieved, not when there is nothing left to add, but when there is nothing left to take away. (Antoine de St. Exupery).
    W3Schools | XHTML Validator | CSS Validator | Colours | Typography | HTML&CSS FAQ | Go get Mozilla Now | I blog!

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Location
    Sheffield, UK
    Posts
    552
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thats exactly the reason

    run an str replace to delete all occurances of \r

    as for matching double line breaks why not use "'\n\n's" ? ( i use a single quote as a delimiter)
    "To be successful in IT you don't need to know everything - just where to find it in under 30 seconds"

    (Me Me Me Me Me Me Me Me Me)

  • #4
    me'
    me' is offline
    Senior Coder
    Join Date
    Nov 2002
    Location
    Warwickshire, England
    Posts
    1,229
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Finally got it to work! Thanks! Here's my final code:
    Code:
      $postnew = str_replace("\r", '', $_POST['post']);
      $postnew = str_replace("\n\n", "[ot]/paragraph[ct]\n\n[ot]paragraph[ct]", $postnew);
    David House - Perfect is achieved, not when there is nothing left to add, but when there is nothing left to take away. (Antoine de St. Exupery).
    W3Schools | XHTML Validator | CSS Validator | Colours | Typography | HTML&CSS FAQ | Go get Mozilla Now | I blog!

  • #5
    Mega-ultimate member
    Join Date
    Jun 2002
    Location
    Winona, MN - The land of 10,000 lakes
    Posts
    1,855
    Thanks
    1
    Thanked 45 Times in 42 Posts
    Just a comment,

    Thanks for posting your solution. All to often I notice people get things to work and simply post something like "I got it, thanks". Although this is great, It really annoys me when I search this forum and can't find the answer because it wasn't added at the end of the thread.

    I know I too am guilty, but I just wanted to point it out and say thanks me'

  • #6
    Regular Coder
    Join Date
    Jun 2002
    Location
    Sheffield, UK
    Posts
    552
    Thanks
    0
    Thanked 0 Times in 0 Posts
    am i correct to assume that you later change all occurances of [ot] and [ct] into < and > respectively?
    "To be successful in IT you don't need to know everything - just where to find it in under 30 seconds"

    (Me Me Me Me Me Me Me Me Me)

  • #7
    me'
    me' is offline
    Senior Coder
    Join Date
    Nov 2002
    Location
    Warwickshire, England
    Posts
    1,229
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Originally posted by bcarl314
    I know I too am guilty, but I just wanted to point it out and say thanks me'
    No problem
    am i correct to assume that you later change all occurances of [ot] and [ct] into < and > respectively?
    Yep, I was passing a string with < and > into an XSLT file, and getting well formed errors, so I swapped out < and > with [ot] and [ct], and use another str_replace later on.
    David House - Perfect is achieved, not when there is nothing left to add, but when there is nothing left to take away. (Antoine de St. Exupery).
    W3Schools | XHTML Validator | CSS Validator | Colours | Typography | HTML&CSS FAQ | Go get Mozilla Now | I blog!


  •  

    Posting Permissions

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