- 7 months ago 23
HTML Question

Using PHP to add line breaks to TextArea

I want to add Line break in a textarea placeholder using php.


<!DOCTYPE html>
<html style="height: 100%;">


<div id="editContainer">
<textarea id="note" name="note" placeholder="Placeholder Text"></textarea>


This Should Work:

<textarea placeholder="<?php
$data = 'Line Number One,-,Line Number Two';
$ndata = str_replace(',-,',"\n",$data);
print "$ndata"; ?>"></textarea>

You can change the ,-, in the third line to anything that suits you.

Here's some pointers:

  • Make sure you rename your file to .php
  • Make sure you use a local server or online server to parse the code.
  • HTML Comments are Written as <!--Comment--> not as //comment(that's JavaScript)