Jump to content

Script to display CSV file on Website


Aaronj5

Recommended Posts

Hello,

 

This is my first post, and I know very little about PHP, which is why I'm glad I found this site, and I hope that some of you can help me understand what I'm doing.

 

I've been tasked with writing some sort of script to format and display the contents (or certain parts) or a CSV file on a website.  The website is http://www.coolcowzone.com.  I'm the webmaster for a small company, as well as a litany of other things, mostly IT related.  Unfortunately, I'm way over my head in terms of trying to write code to accomplish this, and am hoping someone here can give me ideas or examples.

 

I've already searched online for a couple of hours, as well as here, and tried a few different scripts off some help sites, all to no avail.  I know I'm doing something wrong, but can't figure out for the life of me what it is!

 

If you'd like to see some of the scripts I've tried, or need more information, just ask.

 

Thanks,

-Aaron

Link to comment
https://forums.phpfreaks.com/topic/139105-script-to-display-csv-file-on-website/
Share on other sites

coma separated values, you can use, the following functions,

<?php
$filename = 'somefile.txt';  //csv file
$delimeter = ',';  //the stuff separating the values

$csvstring = file_get_contents($filename);  //reads a files contents into a string....
$csvarray = explode($delimeter, $csvstring);

print_r($csvarray);  //prints readable contents of the array

/*
print_r outputs the following:

array([0] => 'value1',
      [1] => 'value2',
      [2] => 'value3',

       ......and so on....

to only display certain value you would sort through the csv array, using other functions that would help you sort, like preg_match(), strstr(), strpos(); in_array(); ect... :-)
*/

 

hope that helps some... :-)

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.