Preserving Tabs in POST Data

£可爱£侵袭症+ 提交于 2019-12-07 12:46:21

问题


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 jQuery plugin 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>

This also doesn't work. Apparently the tabs disappear before the data even reaches the str_replace function (the first double quotes is the result from 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 includes 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.


回答1:


Well it's a bit like killing an ant with a bazooka but you can use the base64 encoding before POST the data:

http://plugins.jquery.com/project/base64

and decode it with:

http://www.php.net/manual/en/function.base64-decode.php

It should work really nice but it's increase a lot the size of your request.



来源:https://stackoverflow.com/questions/2703967/preserving-tabs-in-post-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!