|
Home Pages Pidgin Azarennya (S|N) Mac Textanium Reference ToDo Food Local Edit Local: Hide Weather • GoWhere? • YahooMaps (mine) • GoogleMaps • Metro (map) • FairfaxConnector • GreaterGreaterWashington • DCMetrocentric • WhatsUpArlington • Restonian • BeyondDC • BaconsRebellion Language: Hide Fantasy: Hide • AnnalsOfArda • Arda • SilmarillionChronology • TolkienGateway • SciFi: Hide • CentauriDreams • ColdNavy • ConceptShips • RavenstarStudios • SkyscraperPage • StarTrek • StarTrekVsStarWars • Film: Hide IMDB • BigHollywood • DKnowsAll • Jabootu • KyleSmith Music: Hide REALbasic: Hide • Resources • Garage • University • WebRing • Forums: • REAL • ElfData • Plugins and Code: • BKeeney • DeclareSub • Einhugur • Joe • Restrepo • Tempelmann • ZAZ Coding: Hide Forums: • PowWeb • PHP • Webmaster • Coding • Walkers • Perl • Intro • Monks • PHP • JavaScript • Toolbox • UnobtrusiveJavaScript • JavaScriptCompressor • RegularExpressions (test) • JSLint • SQL • Cocoa • CocoaBuilder • CocoaDev • CocoaLab • AppleScript • BBS • Userland • Faqintosh • FileMaker • FileMakerTips • FileMakerWorld • FileMakerPlugins Science: Hide DarwinCentral • PhysOrg • PandasThumb • TalkOrigins • TalkRational • AstronomyDailyPics • Curmudgeon • SmallThings • ArchaeoBlog • AntiEvolution.org • SkepticsGuide • EvC • BadAstronomer • PhysicsForum • SlashdotScience • JunkScience • Engadget • Thunderbolts • Icecap • CentauriDreams • NewScientist • Gizmodo • CO2Science • ClimateDebate • ScienceDaily • Nrich • Math • TalkOrigins • GoodMathBadMath • Magazines • AmericanScientist • NationalGeographic • Space.com History: Hide • 1421 News/Politics: Hide WideAwakes • Anchoress • Lucianne • Strata • AceOfSpades • BigLizards • BlackAndRight • Cannonfire • DrSanity • FloppingAces • GatewayPundit • HillBuzz • HotAir • Husaria • JawaReport • JimTreacher • JsCafeNette • LittleGreenFootballs • MyVRWC • Newsbusters • Pal2Pal • PinkFlamingo • PowerLine • RachelLucas • RogerLSimon • SisterToldjah • StolenThunder • SultanKnish • TCSDaily • UppityWoman • Wizbang • NewsGroper • NewsRightNow • OriginalSignal • Blogs... Cults/Crime: Hide Miscellaneous: Hide Fun: Agony ICanHas? ObSkills Snopes Pix: Deviant Places Renderosity Blender Artists X86: OSX86 ArsTech OSNews TUAW Tools: Calculator AsciiArt XMLVal FunStuff: Pictures: Photobucket (eg Dubai) Videos: YouTube Subtitler InterestingThings: LibraryThing FlashCards GoogleDocs Wowio Bubbl.us Colemak Audible PodioBooks WonderfulInfo BooksOnline AboutUs.org |
Wiki /
DiscussionFileFormatForEntries
Record-file formatMarkup schemes tend to use four hyphens to mark a horizontal line. Let's take advantage of that, except that we look for lines with four hyphens AND extra data:
Code to retrieve records
$records = array();
$record = array();
$record['text'] = '';
$record['meta'] = '';
while (!feof($handle)) {
$line = getline($handle);
if ($line == '') break;
$head = substr($line, 0, 5);
if ($head == '----#') {
if (match($record, $criteria)) {
$records[] = $record;
}
$record['text'] = '';
$record['meta'] = '';
} elseif ($head == '----:') {
$record['meta'] .= "\n" . substr($line, 5);
} else {
$record['text'] .= $line;
}
}
if ($record['text'] != '' or $record['meta'] != '') {
if (match($record, $criteria)) {
$records[] = $record;
}
}
Code to compare recordsA record's fields are stored as a single string (in $record['meta']). You search for a newline followed by a field name, then check the value after the name against the criteria. Criteria also come as a multiline string, with each criterion (e.g., "name < John") separated from the next with a newline.
function match($record, $criteria) {
// $criteria should be an array of arrays: field name, operator, field value.
// To find phrase in text, field name is "" and operator is "^" (contains).
// For each item in $criteria
// If field name is blank, search $record['text'].
// Else, search $record['meta'].
}
Operators and code:
$match = true;
$value = strtolower($value); // Field value in the record.
$sought = strtolower($sought); // Value in the criterion.
switch ($operator) {
case '^':
if (strpos($value, $sought) === false) $match = false; break;
case '=':
case '==':
if ($value != $sought) $match = false; break;
case '!=':
case '<>':
if ($value == $sought) $match = false; break;
case '<':
if ($value >= $sought) $match = false; break;
case '<=':
if ($value > $sought) $match = false; break;
case '>':
if ($value <= $sought) $match = false; break;
case '>=':
if ($value < $sought) $match = false; break;
case '!^':
if (strpos($value, $sought) !== false) $match = false; break;
default:
$match = false;
}
|