如何使用 PHP 验证上传文件包含制表符分隔数据?
我想验证上传的文件是否用制表符分隔符分隔。我的文件不是 .CSV
。有谁知道如何在 PHP 中做到这一点?提前致谢。
I want to validate that an uploaded file is separated with tab delimiter. My file is not .CSV
. Does anyone knows how to do this in PHP? Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不是 100% 清楚你要什么(也许你可以发布一些例子)这可能会对你有所帮助:
搜索制表符:
"\t"
双引号很重要。如果您有字符串中的选项卡式项目列表并希望将其转换为数组,您可以使用explode( )
并输入“\t”作为第一个参数。I'm not 100% clear what you are asking for (maybe you could post some examples) This might help you anyway:
Search for the tab character:
"\t"
The double quotes are important. If you have a list of tabbed items in a string and want to turn it into an array you can useexplode()
and enter "\t" as the first argument.看看我在这篇文章中的代码:
如何确定 csv 文件字段是制表符分隔还是逗号分隔
基本上,您比较每行中的制表符数量。如果 CSV 的每一行都有相同数量的制表符,那么它可能是制表符分隔文件。请注意,这不会是 100% 的情况,这是验证的一个很好的起点。
Take a look at my code in this post:
how to find out if csv file fields are tab delimited or comma delimited
Basically, you compare the number of tabs in each row. If every row of your CSV has the same number of tabs, then it is probably a tab delimited file. Please note, this will not be the case 100% of the time, it's a good starting point for validation.