Skip to content

Instantly share code, notes, and snippets.

@walterdavis
Last active December 11, 2015 01:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save walterdavis/4520957 to your computer and use it in GitHub Desktop.
Save walterdavis/4520957 to your computer and use it in GitHub Desktop.
<?php
$out = '';
$template = '<div class="photo">
<img src="/photos/%s" alt="%s" />
<h3>%s</h3>
<p>%s</p>
</div>
';
$max_length = 1000; //longest line in your data
if (($handle = fopen("test.csv", "r")) !== FALSE) {
while (($data = fgetcsv($handle, $max_length)) !== FALSE) {
if(count($data) >= 3){
$out .= sprintf($template, $data[1], $data[0], $data[0], $data[2]);
}
}
fclose($handle);
}
print $out;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment