How to Remove Carriage return and line feeds.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • coolguyraj
    New Member
    • Jun 2007
    • 8

    How to Remove Carriage return and line feeds.

    Hi.

    I have form that has a text box. I want insert unformatted text into the database.
    Even if the user gives an carriage return or New line feed in the database it should be stored as on single line without any formatting.

    I just want to remove
    New Line Feed(\n)
    Carriage Return(\r)
    spaces at the begin and end of the string.

    Eg:
    If i have
    text1(enter key pressed)
    text2(enter key pressed)
    text3(enter key pressed)
    Blank space
    Blank space

    I want this to be stored in the DB as:
    text1 text2 text3

    Could someone help me with this?

    Thanks
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    For removing characters you can use the str_replace() command.

    We can help you when you start writing your own code. Then come back here when you run into problems or have questions. We do not supply ready made code.

    Ronald

    Comment

    • coolguyraj
      New Member
      • Jun 2007
      • 8

      #3
      I already have the code ,Everything works fine but i want to store the data from a textarea without any formatting into the database.

      Currrently it stores data with formatting like (\n)(\r)
      i want to strip them off. and use one single line with spaces between words.

      i used str_replace() but that does not seem to work.

      Can someone helpme with this.

      Thanks

      Comment

      • aktar
        New Member
        • Jul 2006
        • 105

        #4
        Try str_replace() with ascii codes

        Comment

        • ronverdonk
          Recognized Expert Specialist
          • Jul 2006
          • 4259

          #5
          Show your str_replace command here. I wonder if you defined the \n and \r within single quotes. When you did: that does not work. You have to include them within double quotes.

          Show your str_replace() command anyway (within code tags)

          Ronald

          Comment

          Working...