SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast AimyThomas's Avatar
    Join Date
    Sep 2011
    Posts
    46
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Clean and keep line breaks

    Hello,

    I want to keep line spaces in comments but clean more then 2 after each.

    Example:

    $sentence="This is my first sentence
    This will be in a new row
    This will be too in a new row but not separated with 3line breaks just with

    one

    ";
    And i want to output just this:

    $sentence="This is my first sentence
    This will be in a new row

    This will be too in a new row but not separated with 3line breaks just with
    one
    ";
    Please Help

    Thanks in Advance

  2. #2
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,147
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by AimyThomas View Post
    Hello,

    I want to keep line spaces in comments but clean more then 2 after each.

    Example:

    $sentence="This is my first sentence
    This will be in a new row
    This will be too in a new row but not separated with 3line breaks just with

    one

    ";
    And i want to output just this:

    $sentence="This is my first sentence
    This will be in a new row

    This will be too in a new row but not separated with 3line breaks just with
    one
    ";
    Please Help

    Thanks in Advance
    First there seems to be an issue with your examples.

    You have the following as your input
    PHP Code:
    $sentence="This is my first sentence
    This will be in a new row
    This will be too in a new row but not separated with 3line breaks just with

    one

    "

    And then this as your wanted output
    PHP Code:
    $sentence="This is my first sentence
    This will be in a new row

    This will be too in a new row but not separated with 3line breaks just with
    one
    "

    What are the business rules for establishing an extra line break after "This will be in a new row" (since it wasn't part of the input)?

    If you are trying to reformat the user's entire comment, I'm going to suggest stopping right there! You are playing with grammar and the user may have written it correctly and after you reformat it, the comment might not make any sense anymore or worse, it may take on an entirely different meaning.

    If you are trying to remove any extra line breaks at the end of the comment, that is an easy task (using rtrim).


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
  •