cash.io.co cash.io.co - 6 months ago 17
HTML Question

Using PHP to add line breaks to TextArea

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

Code:

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

<head>
//stuff
</head>

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

Answer

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)