
Originally Posted by
anonymouse
I don't really know how to implement functions...
Is that implement functions, or use them? There's a bit of a difference. 
so where do I define each of the arguments?
That depends on whether you'd want to use them again. You could place the value of each argument in-line with the function call:
PHP Code:
myFunction('a string', 32, anotherFunction());
assign the values to variables first:
PHP Code:
$arg1 = 'a string';
$arg2 = 32;
$arg3 = anotherFunction();
myFunction($arg1, $arg2, $arg3);
(hopefully using better names), or a mixture of the two as necessary.
Where do I put the line that establishes the lineNum, handle, etc [...]
Well, that's up to you (as I said above)...
If it's easier, maybe you could just show me an example, say, for instance, if I want line 3 (three) of a file "rate.txt"
...but I'll use variables for this example because it's probably clearer.
PHP Code:
$desiredLine = 3;
$filename = 'rate.txt';
/* The @ suppresses any error messages that
* might result from the function call.
*
* As we only want to read from the file,
* it will be opened for reading only.
*/
$fileHandle = @fopen($filename, 'r');
/* However, we can still check if the call
* succeeded because if it failed,
* $fileHandle will evaluate to false.
*/
if(!$fileHandle) {
/* File open operation failed. Do error
* handling here.
*
* Handling mechanisms should be more
* graceful, but for simplicity, we'll
* simply stop execution.
*/
exit();
}
$line = readLine($desiredLine,
$fileHandle);
I hope that helps,
Mike
Bookmarks