We'd love to hear from you! Provide  feedback  to earn a badge today. Take our quick survey
You're almost there! Please answer a few more questions for access to the Applications content. Complete registration
Interested in joining? Complete your registration by providing Areas of Interest here. Register

What is the best way to read a CSV file in OSvC

Received Response
19
Views
3
Comments
edited Sep 15, 2019 10:38AM in Customer Portal 3 comments

Content

Hi,

I'm currently using the below to read a CSV file into an array but I was wondering if there was a trick I was missing in OSvC / RNCPHP?

private function csvToArray($filename) {
RNCPHP\ConnectAPI::getCurrentContext()->ApplicationContext = "Putting a CSV file into an array";
try{
// Declare variables
$data = array();
$filename = HTMLROOT . "/euf/assets/csv/".$filename;
 
// Process CSV
if (($handle = fopen($filename, "r")) !== FALSE) {
while (($line = fgetcsv($handle, 1000, ",")) !== FALSE) {
$data[] = $line;
}
}
}
catch ( \Exception $err ){
echo "<br><b>Exception</b>: line ".__LINE__.": ".$err->getMessage()."</br>";
}
 
return $data;
}
Thanks,
 
JJ

Howdy, Stranger!

Log In

To view full details, sign in.

Register

Don't have an account? Click here to get started!