preg_match_all 令人困惑的失败
$string = (string) file_get_contents($_FILES['file']['tmp_name']);
echo $string;
// Correctly echos string contents
preg_match_all("/[\._a-zA-Z0-9-]+@[\._a-zA-Z0-9-]+/i", $string, $matches);
print_r($matches);
// No matches
我正在解析文本/csv 文件并从上传的文件中获取电子邮件地址。当解析 Google 联系人文件时,我导出它奇怪地失败了。但是,当我简单地复制回显的字符串并粘贴它而不是 file_get_contents 结果时,它就会解析并工作。
知道为什么它拒绝接受 file_get_contents
字符串,但如果我自己粘贴原始数据,它会起作用吗?
$string = (string) file_get_contents($_FILES['file']['tmp_name']);
echo $string;
// Correctly echos string contents
preg_match_all("/[\._a-zA-Z0-9-]+@[\._a-zA-Z0-9-]+/i", $string, $matches);
print_r($matches);
// No matches
I am parsing text/csv files and grabbing email addresses from uploaded files. When parsing a Google Contact file I exported it weirdly fails. But when I simply copy the string that is echo'd and paste that instead of the file_get_contents result, it parses and works.
Any idea why it is refusing to take the file_get_contents
string, but if I paste in the raw data myself, it works?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
$_FILES['file']['tmp_name']
是一个临时上传的文件,在调用file_get_contents
之前应该先移动到一个目录,例如$_FILES['file']['tmp_name']
is a temporary uploaded file, you should move to a directory first before callingfile_get_contents
, like