PHP Find String in CSV file

后端 未结 6 1165
无人及你
无人及你 2020-12-17 17:36

I\'ve got a large flat file of usernames and emails in the following format:

\"username\", \"email\"
\"username\", \"email\"
\"username\", \"email\"
<         


        
6条回答
  •  醉话见心
    2020-12-17 17:42

    I think the easiest solution is to use file() with str_getcsv().

    The code would be something like this:

    foreach (file($fileName, FILE_SKIP_EMPTY_LINES) as $line) {
        $columns = str_getcsv($line); // Where $columns[0] and $columns[1] hold the username and email respectively.
    }
    

提交回复
热议问题