Dr. Andrew Besmer
fopen($fileName, $mode) - returns a resource to the file or false, if it was unable to open filefgets($resource) - returns a string up to a CRLF or EOF, if it runs out of data to read false is returnedfwrite($resource, $content) - returns number of bytes written or falsefclose($resource) - returns true if the file is successfully close, false if notr - Readw - Write (erase file if exists, create if not)a - Append (create if does not exists, appends to end)callList.csvDictum Eu Company,1-194-286-3041
Proin Industries,1-319-137-9279
Enim Sit Industries,1-562-872-9219
Phasellus In Corp,1-128-930-9807
Dolor Quam Elementum PC,1-928-801-9652
Nibh Lacinia Orci PC,1-332-594-5321
Donec Porttitor Tellus Company,1-873-991-8646
Ut Dolor Consulting,1-514-308-9570
Suspendisse Ac Metus PC,1-466-488-2655
Lorem Incorporated,1-778-863-7253
Curabitur Consequat Incorporated,1-496-807-1201
Non Company,1-383-777-6247
Enim Inc,1-441-333-2507
Quisque Libero Industries,1-821-364-5581
At Pretium Aliquet Incorporated,1-651-831-1982
Mi Consulting,1-358-903-2637
Lacus Varius LLP,1-493-938-0338
Nibh Dolor Foundation,1-706-129-8454
Risus Associates,1-657-994-6688
Viverra LLC,1-857-231-3877
Nunc Corp,1-652-403-0424
Praesent Luctus Curabitur Foundation,1-363-243-2228
Risus PC,1-110-328-3877
Eleifend Nunc Risus Associates,1-873-927-9209
Vel Convallis LLP,1-430-846-6335
fopen() the file by providing the location and moderesource
$callList = fopen("callList.csv", "r");
if(!is_resource($callList))
{
echo "Could not open file";
exit();
}
//Do stuff with your file
fclose($callList);
fgetscsv() to parse csv but we would limit our learning today :)fgets()//Open the file
while($line = fgets($callList))
{
echo $line;
}
//Close the file
$line contain during each iteration?//How can we turn this:
"Dictum Eu Company,1-194-286-3041"
//Into this:
array("Dictum Eu Company", "1-194-286-3041");
explode($delimiter, $source) - returns an array of strings by splitting it up using the delimiterimplode($delimiter, $source) - returns a string by combining all the elements of the array inserting the delimiter between each$companies[]=explode(",", $line);
$line = implode(",",array("Dictum Eu Company", "1-194-286-3041"));
callList.csv what will be in $companies[0]?in_array($needle, $haystack) - Searches the haystack (array) for the needle (element) and returns true if found, false if not<?php
$colors = array("red", "green", "blue");
indigo is in the variable $colors using in_array()?in_array("indigo",$colors);
array_search($needle, $haystack) - Searches the haystack (array) for the needle (element) and returns the key (or index) if found, false if notWe are assuming that the csv file is a very simple one here. This in reality is a terrible assumption.↩