Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to preserve tabs from textarea POST data

This is a simple question; I will make it simple.

So I've got a <textarea name="textarea"> in a <form method="POST">

<?php
$textarea = $_POST['textarea'];

echo nl2br($textarea);

Solves maintaining the NEW LINES,

But how do I maintain TABS?

tab2tab() or something?

like image 202
khaverim Avatar asked Aug 07 '12 21:08

khaverim


1 Answers

Although, not designed for this specific use, you can do:

$textarea = str_replace("\t", "     ", $_POST['textarea']);

Or if you want the HTML equivalent of a space:

$textarea = str_replace("\t", "&nbsp;&nbsp;&nbsp;&nbsp;", $_POST['textarea']);
like image 108
Mike Mackintosh Avatar answered Oct 13 '22 00:10

Mike Mackintosh