Solved

PHP4 - Show Multiline Output From Multiline Textbox (Send Email)

Posted on 2004-03-23
2
423 Views
Last Modified: 2010-08-05
PHP4 Email (HTML Format)

Here is my code which it can't work

  <tr>
    <td colspan="2">'.htmlspecialchars(str_replace(chr(13).chr(10), "<br>", $_POST["txtDescription"])).'</td>
  </tr>

Input
------
Line 1
Line 2
Line 3

Output
-------
Line 1<br> Line 2<br> Line 3

How to make it show in multiline? pls advise.

Thanks
0
Comment
Question by:ztot
2 Comments
 
LVL 1

Expert Comment

by:j_chakraverty
ID: 10671954
YOUR ERROR:
--------------------
    your error was use of chr(13) and chr(10) use \r \n for carriage return and linefeed in php

SOLUTION
--------------
    I am giving a piece from one of my projects it has been under test for long and in pretty many projects its bound to work
    I made it a function as i use it many times over. So its in an include file and is

function FormatForWeb($stringMain)
{
    $stringMain=eregi_replace("\n","<br>",$stringMain);
    return $stringMain ;
}

-----------------
EXAMPLE USE
-----------------
to use I am using the same varibles a sgive in your question ie $_POST["txtDescription"] from this line i assume that you have a text box named 'xtDescription' instead of $_POST["txtDescription"] I am using variable '$txtDescription'. This is same as php automativcally creats any variable from the POST data

           $toPrint=FormatForWeb( $txtDescription);
            print $toPrint;

           -----------------
           'more unreadable alternative is many people believe such cryptic coding is power coding
           'but analysying this code u shall see its just saves space and no performance differance

           print(FormatForWeb($txtDescription)
----------------------------
additional function
----------------------------
just for sake of completion iam giving below the other function that takes a html and makes it a regular crlf saparated strinfg useful if you need to paste in some text box or something
function FormatForWeb($stringMain)
{
    $stringMain=eregi_replace("<br>","\n",$stringMain);
    return $stringMain ;
}
---Regards and have fun
0
 
LVL 3

Accepted Solution

by:
odders earned 50 total points
ID: 10673033
yes, \n is generally how newline is specified

try using the function nl2br() this doesnt just convert new lines to <br />'s, it retains the new line as well, so that your output is multi line. try this:

  <tr>
    <td colspan="2">'.echo(nl2br(htmlspecialchars($_POST["txtDescription"]))).'</td>
  </tr>

if you want to keep the char spacing even (which is always good for emails), i would persoanlly just stick it in pre tags, like this:

  <tr>
    <td colspan="2"><pre>'.echo(htmlspecialchars($_POST["txtDescription"])).'</pre></td>
  </tr>

that will echo your everything exaclty as it was typed.

hope thats what your after...
0

Featured Post

ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
cmd.exe will not close when running .bat file to perform FTP upload 18 103
This code tracks birthdays 3 73
simplest php form 3 79
ASP/VB email question 4 35
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question