Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Remove newlines from a variable

Status
Not open for further replies.

PS1983

Technical User
Nov 6, 2001
83
AT
Hi!
I'm just trying to code a guestbook (for excercise purposes only), where I have a formular with 2 text inputs and a textarea field.
The entries are written in a textfile:
E.g:
Somebody Name|somebody@name.com|Some message a guy left|Timestamp|
The whole entry is one line of my file.

Now my problem is that when the message contains newlines (paragraphs,or whatever :))the variable is written in more lines, keeping the newlines as they are...

I have tried several methods, but they didn't work out.

Maybe you can help me, I would appreciate it very much!

Thank you, bye
Steve


 
$textarea = str_replace("\n","<br>",$textarea);

works wonderful!
I just had the variable mispelled. =(

Thank's for your help!

 
Additional information under unix you need to filter \n and \r
then it works
$message2=str_replace("\r"," ",$message2);
$message2=str_replace("\n"," ",$message2);


Bye, steve


 
if that was the problem then also consider the nl2br function

$strText = nl2br($textarea);

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top