如何在PHP中验证上传的CSV文件内容? [英] How do I validate uploaded CSV file contents in PHP?

查看:270
本文介绍了如何在PHP中验证上传的CSV文件内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以验证上传的CSV文件的所有字段,并且如果任何验证使用PHP失败将显示所有错误



例如我有一个由用户上传的CSV文件,其中包含以下内容:



姓名,工作,年龄

John,Clerk,23

Debra,经理,32

1A3ce ,, 40a



验证将是:



如果名称包含数值,则向用户显示错误

如果Age包含非数字值,则向用户显示错误

如果年龄相等或小于零,向用户显示错误

如果作业长度超过15个字符,则向用户显示错误

如果任何字段没有值或者它是空白,向用户显示错误



你是怎么做到的?我对PHP知之甚少,至少有关如何编写代码的指南对我有很大帮助。



我尝试了什么:



我真的不知道如何开始编码..我真的需要帮助。

Is it possible to validate all the fields of an uploaded CSV file and will display all errors if any of the validations fail using PHP

For example I have a CSV file uploaded by a user which contains these:

Name,Job,Age
John,Clerk,23
Debra,Manager,32
1A3ce,,40a

Validations will be:

If Name contains numeric value, display error to the user
If Age contains non-numeric value, display error to the user
If Age is equal or less than zero, display error to the user
If Job exceeded 15 characters in length, display error to the user
If any of the fields does not have a value or it is blank, display error to the user

How do you do this? I have little knowledge in PHP and at least a guide on how to code this will help me greatly.

What I have tried:

I don't really know how to start coding this.. I really need help.

推荐答案

您首先需要学习PHP: PHP 5教程 [ ^ ]。
You first need to learn PHP: PHP 5 Tutorial[^].


这篇关于如何在PHP中验证上传的CSV文件内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆