Textarea & PHP

by 4 replies
5
Hi

I am trying to create a PHP which collects name & address then save it as txt file but having hard time getting one of the variable to put information in one cell.

The script is

Input1 Name
Input2 Tel No
Input3 Address

Input3 is textarea with may be more than 2 lines.

Output I want is all in one row.

Column 1 Name1
Column 2 Tel1
Column3 Address ( all lines as one cell)

So all of this is one line. Next line for next name and so.

I can get column1 and column2 to work but address columns gets all out of line. This is what I end up

Row1 Column1 Name1
Row1 Column2 Tel no
Row1 Column3 Address line1
Row2 Column3 Address line2
Row3 Column3 Address line3
Row3 Column1 Name2
Row3 Column2 Tel No


Is there a solution for this?

Thanks
Sukh
#programming #php #textarea
  • hey there

    posting a snippet of your code may help with your question... so ppl can get a visual

    also, it's possible that you need to strip the "newline" and/or "carriage return" characters from the textarea when it is submitted.

    peace

  • Hey can you post your source code. Hard to debg coose you can not see. If you can I will be glad to have a look for ya..
    • [1] reply
    • Hi

      here is the script

      Code:
      
      this is the function in PHP
      
      
      
      if (isset($_POST['update']))
      {
      	$delimiter = "|";
      	$name = $_POST['name'];
      	$tel=$_POST['tel'];
      	$address=$_POST['address'];
      	$filename = "test.txt";
      	$fp = fopen($filename, "w");
      	$con = $name . $delimiter . $tel . $delimiter . $address."\n"; 
      	fwrite($fp, $con);
      	fclose($fp);
      	echo "Update Compeleted";
      	
      }
      
      
      	
      ********************	
      
      thi is Code on the page
      
      <form id="form1" name="form1" method="post" action="">
      
      <table>
      	
      	<tr>
      		
      		<td> <b> Name :    </b></td>
      	</tr>
      	<tr>
      		
      	
       		<td><input type="text" size="100" name="name" id="name" /></td>
      	</tr>
      	
      	<tr>
      		
      		<td><b>Tel :  </b></td>
      	</tr>
      	<tr>
      		
       		<td><input type="text" size="100" name="tel" id="tel" /></td>
      	</tr>
      	
      	<tr>
      		
      		<td><b> Address :  </b> </td>
      	</tr>
      	<tr>
      		
      		<td><textarea rows="10" cols="100" name="address" id="address"></textarea></td>
      	</tr>
      	
      	<tr>
      	
      		<td><input name="update" type="submit" id="update" value="Update" /></td>
      	</tr>
      </table>
      	
      </form>
      All address data needs to be in one cell in one column.

      Thank for your help
  • REPLACE:

    $address=$_POST['address'];

    WITH:

    $address = str_replace(array("\n","\r"),', ',$_POST['address']);

    As imarketstuff suggested, that will replace all line breaks with a comma.

    Line 1
    Line 2
    Line 3

    will be saved as Line 1, Line 2, Line 3

    -Ryan

Next Topics on Trending Feed

  • 5

    Hi I am trying to create a PHP which collects name & address then save it as txt file but having hard time getting one of the variable to put information in one cell.