在插入 php 之前验证 csv 文件的电子邮件列 [英] Validate email column of csv File before insertion in php
问题描述
我在插入 php 之前使用了正则表达式来验证 csv 文件的电子邮件列.但是当我使用正则表达式或过滤器验证电子邮件功能时,它总是以不正确的格式显示电子邮件,尽管我在 csv 文件中有正确的电子邮件格式.我希望它读取一个 csv 文件并检查 csv 文件中的电子邮件列并检查它的值,即电子邮件中的值是否应该是正确的格式.如果格式正确,则数据插入否则跳过.
Hi i have used regular expression for validating email columns of csv file before insertion in php.but when i used regular expression or filter validate email function it always show emails in incorrect format although i have a correct email format in csv file.I want that it read a csv file and check email column in csv file and check its value i.e in email should be in correct format or not.If it is correct format then the data insert otherwise skip.
推荐答案
您可能希望在 php 之外过滤文件,然后插入.
you might like to filter the file outside of php, then insert it.
你可以像这样使用 grep
You could use grep like
grep -E "\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,6}\b" file.txt > file-out.txt
但值得指出的是,即使电子邮件可能与正则表达式匹配,它也可能仍然无效.您可以使用 真实电子邮件 之类的服务来为您验证文件.这样您就可以检查电子邮件地址是否确实存在并且处于活动状态.
But its worth pointing out that even though an email might match the regex it might still be invalid. You could use a service like Real Email to validate the files for you. That way you can check if the email address actually exists and is active.
这篇关于在插入 php 之前验证 csv 文件的电子邮件列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!