开发者

preg_match_all confusing failing

$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?


$_FILES['file']['tmp_name'] is a temporary uploaded file, you should move to a directory first before calling file_get_contents, like

$tmp_file = '/tmp/test.csv'
move_uploaded_file($_FILES['file']['tmp_name'], $tmp_file);
$string = file_get_contents($tmp_file);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜