Jump to content

how to print variable from form with carriage returns?


satre

Recommended Posts

I'm sure there's a simple answer to this but I'm just stuck on it... I have a text box in an html form that the user will type several lines similar to this (text and associated number) into:

 

supraspinatus sprain-strain, 840.6

shoulder sprain-strain, 840.9

 

and when I pass the info to be processed via POST to my php, the variable that represents what was typed in is put all together and prints out like this:

 

supraspinatus sprain-strain, 840.6 shoulder sprain-strain, 840.9

 

How can I get it to print out as it was entered?

 

Thanks!

Satre

Sorry, code is nothing fancy. Here's the HTML on the form that people will type words followed by a number and then hit return, type more words followed by the associated number and so on:


<textarea name="icd9codes" id="icd9codes" cols="70" rows="5">
</textarea>

 

and here is the php code that gets the variable and prints it:

if(isset($_POST['icd9codes'])) {
$icd9codes = $_POST['icd9codes'];

echo "ICD9 Codes = $icd9codes <br />";

}

 

If I type this:

 

blah blah blah, 123

blee blee blee, 456

 

(with a return after the 123 so I can be on a new line in the HTML text input) it will print out all on one line with a space where I would like a carriage return to be, like so:

 

blah blah blah, 123 blee blee blee, 456

 

Ideally, I would like to take the input and output it to a table where the words are in the left column, and their associated numbers are in the right column...

OK, thanks! Your suggestion worked:

if(isset ($_POST['icd9codes'])) {
$icd9codes = $_POST['icd9codes'];

echo nl2br("ICD9 Codes = $icd9codes <br />");

 

What if I wanted to take this variable and break it up into an array of just (words, number, words, number,...)? Would I use explode() for that? That might be easier to put into a table...

and what if user will enter just numbers? ^^

use <select> </select> <input value="value">

and so on... easier to handle and to escape exactly what you need.

 

to get only numbers you can use few ways.

check out strings from php.net -> http://php.net/manual/en/ref.strings.php

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.