skip to main | skip to sidebar
Cloud Nebula

Thursday, November 11, 2010

Convert string with carriage returns to one line in php

I have a database string containing new lines characters (\n) and needed to print it out with no linebreaks -- since it was being printed as a javascript variable. This script does the trick:

$input = trim( preg_replace( '/\s+/', ' ', $input ) );

courtesy: http://www.codingforums.com/showthread.php?t=137009
Posted by Brian at 8:10 PM

No comments:

Post a Comment

Newer Post Older Post Home
View mobile version
Subscribe to: Post Comments (Atom)

Blog Archive

  • ►  2011 (9)
    • ►  November (1)
    • ►  July (1)
    • ►  April (2)
    • ►  February (2)
    • ►  January (3)
  • ▼  2010 (33)
    • ▼  November (3)
      • Convert string with carriage returns to one line i...
      • Print booklets on Mac
      • Create AIR app without a taskbar icon
    • ►  October (7)
    • ►  September (10)
    • ►  June (2)
    • ►  May (4)
    • ►  March (1)
    • ►  February (3)
    • ►  January (3)
  • ►  2009 (26)
    • ►  December (1)
    • ►  November (1)
    • ►  October (3)
    • ►  September (6)
    • ►  August (2)
    • ►  June (1)
    • ►  March (1)
    • ►  February (5)
    • ►  January (6)
  • ►  2008 (70)
    • ►  December (4)
    • ►  November (10)
    • ►  October (6)
    • ►  September (1)
    • ►  August (4)
    • ►  July (2)
    • ►  May (6)
    • ►  April (13)
    • ►  March (7)
    • ►  February (9)
    • ►  January (8)
  • ►  2007 (7)
    • ►  December (7)

About Me

My photo
Brian
View my complete profile