Created
October 29, 2012 08:23
-
-
Save Macagare/3972324 to your computer and use it in GitHub Desktop.
PHP: Open and read a csv file via PHP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$fh = fopen("myfile.csv", "r"); | |
while ($line = fgets($fh)) { // Read one line at-a-time until end of file | |
$words = explode (';', $line ); // break the line down to words, by separating on a ';' | |
echo "This line consisted of the following words:\n"; | |
foreach ($words as $word) { //display all words | |
echo "Word: ". $word. "\n"; | |
} | |
// update the database here. | |
} | |
fclose($fh); | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$fh = fopen("myfile.csv", "r"); | |
while ($line = fgets($fh)) { // Read one line at-a-time until end of file | |
$words = explode (';', $line ); // break the line down to words, by separating on a ';' | |
echo "This line consisted of the following words:\n"; | |
foreach ($words as $word) { //display all words | |
echo "Word: ". $word. "\n"; | |
} | |
// update the database here. | |
} | |
fclose($fh); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment