satre Posted March 16, 2010 Share Posted March 16, 2010 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 Quote Link to comment Share on other sites More sharing options...
StathisG Posted March 16, 2010 Share Posted March 16, 2010 I don't understand what do you want to print exactly. Also, post your code. Quote Link to comment Share on other sites More sharing options...
satre Posted March 16, 2010 Author Share Posted March 16, 2010 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... Quote Link to comment Share on other sites More sharing options...
LeadingWebDev Posted March 16, 2010 Share Posted March 16, 2010 i believe it should looks like nl2br($_POST['index']); to keep the \n\r if entered alright, nl2br(); is for you. Quote Link to comment Share on other sites More sharing options...
satre Posted March 16, 2010 Author Share Posted March 16, 2010 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... Quote Link to comment Share on other sites More sharing options...
LeadingWebDev Posted March 16, 2010 Share Posted March 16, 2010 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.