检测文本区域中复制的选项卡以进行数据库输入
我有一个文本区域,可以让用户编写自己的输入,并将其保存到数据库中。
大多数用户从 Word 或类似程序复制文本,这些程序也会将选项卡复制到文本区域中。
当选项卡保存到数据库时,它会自动将它们转换为一个空格。
我想将选项卡保存为数据库中的正确选项卡或一组空白,但是我无法首先捕获这些选项卡。
这是我到目前为止所尝试过的(在从用户获取输入之后并在保存到数据库之前)
str_replace("\t", " ", $string);
str_replace(chr(9), " ", $string);
但是,我可以说选项卡甚至没有被捕获,因为我尝试这样做:
if (strpos($string, "\t") !== false)
{
exit("The tab was found");
}
“退出”永远不会被调用。
我已经广泛搜索了这个问题的答案,但是我还没有找到任何修复方法。
我真的很感激对此的一些帮助。
I have a textarea that lets users write their own input which gets saved into the database.
The majority of the users copy their text from word or similar program, which also copies their tabs into the textarea.
When the tabs get saved to the database it is automatically converting them to just one space.
I want to save the tabs as either proper tabs into the database or a set number of whitespaces, however I can't catch the tabs in the first place.
This is what I have tried so far (after getting the input from the user and before saving to the database)
str_replace("\t", " ", $string);
str_replace(chr(9), " ", $string);
However, I can tell that the tabs aren't even being caught because I try this:
if (strpos($string, "\t") !== false)
{
exit("The tab was found");
}
The 'exit' never gets called.
I have searched extensively for an answer to this, however I haven't been able to find any fixes.
I would really appreciate some help on this one.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Nathan Bell 的评论“在看到值之前是否对表单值进行任何预处理?”。这让我思考。
我使用 codeigniter 作为我的 php 框架。经过一些研究并查看源代码后,我发现内置的安全类将我的所有选项卡格式化为一个空格,就像这样......
所以我所做的就是将源代码更改为:
现在它正在工作。所以感谢内森和其他所有提供帮助的人!
Nathan Bell's comment "Is there any pre-processing being done on the form values before you see the value?". That got me thinking.
I am using codeigniter as my php framework. After doing some research and looking at the source code I found that the built in security class was formatting all my tabs into a single space, like so...
So all I did was change the source code to this:
And it's working now. So thank you Nathan and everyone else who assisted for the help!