Reputation: 7
I need to make script that reads a file delimite by pipes "|" in with binary search without using memory ram. How can I do it?
I tried:
$handle = fopen("myfile.txt", "r");
if ($handle) {
while (($line = fgets($handle)) !== false) {
// while reads line make binary search
}
fclose($handle);
} else {
// error opening the file.
}
myfile.txt
Name|Title|Andrew|TheBook1|July|TheChest|Carol|OneTime
Upvotes: 0
Views: 430
Reputation: 213
Since its homework, I ll give you some tips/steps, you figure out how to implement them :)
blockStart = <first element>, blockEnd = <lastELement>
Upvotes: 1
Reputation: 36964
You can use stream_get_line
to use pipelines as delimiters.
while (($name = stream_get_line($handle, 0, '|')) !== false) {
// if ($name == 'Carol') { ...
}
Upvotes: 1