in a

How to save tabs from POST text data

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

So, I have a <textarea name="textarea"> in a <form method="POST">

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

echo nl2br($textarea);

Decides to keep the NEW LINES,

But how can I support TABS?

tab2tab () or something?

+5
source share
3 answers

Although not intended for this specific use, you can:

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

Or if you need the equivalent of HTML space:

$textarea = str_replace("\t", "&nbsp;&nbsp;&nbsp;&nbsp;", $_POST['textarea']);
+5
source

You don’t need to at all nl2br, it is more a problem of how you tell the browser what to do with all these spaces:

echo "<pre>", htmlspecialchars($textarea), "</pre>";

and what is he. See the <pre>HTML Docs tag , which also reports white-spaceCSS Docs , if you're interested.

+3
source

4 &nbsp; <pre></pre>.

0

All Articles