Results 1 to 3 of 3

Thread: RegEx Help Needed...

  1. #1
    Join Date
    Mar 2006
    Posts
    41
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default RegEx Help Needed...

    I need to replace linefeeds and returns between test from a text box input. There might be any number in any order. For example"
    test\r\r\r\n\r\n\rtest
    Should change to:
    test<SomeString>test
    I've tried:
    PHP Code:
    $data preg_replace("/[\r|\n]*/"'<SomeString>'$original_data); 
    But it doesn't work as I need...

    So, any Reg Ex gurus out there have any suggestions?

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Code:
    $data = preg_replace('/(?:\r?\n)+/', '<SomeString>', $original_data);
    Note the existence of nl2br() if you're attempting to convert them to line breaks, however.Hear hear!
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Mar 2006
    Posts
    41
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by Twey View Post
    Code:
    $data = preg_replace('/(?:\r?\n)+/', '<SomeString>', $original_data);
    Note the existence of nl2br() if you're attempting to convert them to line breaks, however.
    Thanks!

    Actually I'm trying to parse text-box input into an XML file when I can not rely on consistency in how many or what kind of "white space" ends up between paragraphs.

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
  •