Preserving Tabs in POST Data
Posted
by byronh
on Stack Overflow
See other posts from Stack Overflow
or by byronh
Published on 2010-04-24T09:39:22Z
Indexed on
2010/04/24
9:43 UTC
Read the original article
Hit count: 250
I need to preserve tab characters from a textarea through POST Data. It seems that there's no way to differentiate tabs from spaces in the $_POST array, and this is really frustrating me.
I'm using a jQuery plugin from here to allow for tab and shift+tab usage within a textarea. http://teddevito.com/demos/textarea.html
The JavaScript is using this as its TAB character:
$.fn.tabby.defaults = {tabString : String.fromCharCode(9)};
For some reason, it shows an individual space instead of each tab character, so all my code formatting is lost:
<textarea name="field0" rows="26" cols="123"><?php
echo $_POST['field0'];
?></textarea>
Neither does this. Apparently the tabs disappear before the data even reaches the str_replace function (the four spaces in the first double quotes is when I press TAB in my text editor).
<textarea name="field0" rows="26" cols="123"><?php
echo str_replace(" ", "\t", $_POST['field0']);
?></textarea>
The reason I need tabs and not multiple spaces is because my application features and on-line code editor.
Anyone have any ideas? I'm guessing the solution would involve modifying the data with javascript before it's sent through POST, but I haven't the slightest idea how to start.
© Stack Overflow or respective owner