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

Link to comment
Share on other sites

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...

Link to comment
Share on other sites

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...

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.