I have a simple Class for telling the statistics of a CSV file.
One of the methods is for breaking down certain parts of the csv file I specify in the constructor.
I'm not sure how to get those variables selectively, so I just echo them all out. But I want to place them into their own variables for me to grab, after I instantiate the object.
class.OpenCSV.php
<?php
class OpenCSV {
private $filepath;
public function __construct($filepath = __FILE__){
$this->filepath = $filepath;
if(!is_readable($filepath)){
echo("Filepath not found or not readable"."\n");
exit();
}
public function reviewFileStats(){
echo "-----------------------------------\n";
$path_parts = pathinfo($this->filepath);
echo "filepath: \t".$this->filepath. "\n";
echo "dirname: \t".$path_parts['dirname']. "\n";
echo "basename: \t".$path_parts['basename']. "\n";
echo "filename: \t".$path_parts['filename']. "\n";
echo "extension: \t".$path_parts['extension']. "\n";
echo "-----------------------------------\n";
}//eof reviewFileStats
}
?>
showfile.php
<?php
require_once('class.OpenCSV.php');
$csvfile = 'some_csv_file.csv';
$csvObj = new OpenCSV($csvfile);
$csvObj->reviewFileStats();
?>
For now, it displays:
-----------------------------------
filepath: /home/charlie/documents/some_csv_file.csv
dirname: /home/charlie/documents
basename: some_csv_file.csv
filename: some_csv_file
extension: csv
-----------------------------------
And that's great, until I just want to select only one of those items. How do I just retrieve each one separately when calling the method reviewFileStats
I know this is an easy one, but I'm still new to the OO world.