= 1)) { $search = str_replace(' ',' ',$search); } //remove multiple speech marks: while ((substr_count($search,'""') >= 1)) { $search = str_replace('""','"',$search); } //remove speech marks on start or end only if (($search[0] == '"') and ($search[(strlen($search) - 1)] <> '"') or ($search[0] <> '"') and ($search[(strlen($search) - 1)] == '"')) { $search = str_replace('"','',$search); } //define globals so they can be returned by functions $GLOBALS['highlight1'] = ''; $GLOBALS['highlight2'] = ''; $GLOBALS['result'] = ''; $GLOBALS['theurl'] = ''; $GLOBALS['thedate'] = ''; function highlight($thefield,$thefieldlow,$thesearch) { $fieldlength = strlen($thefield); $searchlength = strlen($thesearch); $pos = strpos($thefield, $thesearch); $stringend = $searchlength + $pos; $slice1 = substr($thefield, 0, $pos); $slice2 = substr($thefield, $pos, $searchlength); $slice3 = substr($thefield, $stringend); $GLOBALS['result'] = $slice1.$GLOBALS['highlight1'].$slice2.$GLOBALS['highlight2'].$slice3; //rebuild text with highlight } function getdetails($myurl,$folder,$demo_path,$demo_name,$demo_day,$demo_month,$demo_year) { $filetype_check = substr($demo_path,-4); if ($filetype_check <> '.php') { $filetype = '.html'; } if ($demo_name == 'Using Images To Show Link States') {$filetype = '.html#using';} switch ($folder) { case '': $folder = 'demos/'; break; case 'r': $folder = 'archives/'; break; case 'b': $folder = 'bugs/'; break; case 't': $folder = 'tips/'; break; case 'a': $folder = 'articles/'; break; case 'l': $folder = 'testlab/'; } if ($demo_day <> '') { $GLOBALS['thedate'] = date('jS F Y', mktime(0,0,0,$demo_month,$demo_day,($demo_year + 2000))); } else { $GLOBALS['thedate'] = 'Unknown date'; } $GLOBALS['theurl'] = $myurl.$folder.$demo_path.$filetype; } $title = 'Flat File Database Demo 6'; echo << $title

$title

HTML; if (($search == '') or ($search == '"')) {exit('No usable search string found!');} $fp = fopen('../databases/demos.txt','r'); if (!$fp) {exit('

ERROR: Unable to open database file!

');} $row = 0; while (!feof($fp)) { $col[$row] = fgets($fp,1024); //use 2048 if very long lines $row++; } fclose($fp); //Avoid sort below if you have numbers at the start of each line! //It puts all the lines beginning with 1 first, eg: 1, 10, 11, 12 etc. //sort($col); reset($col); $arrays = count($col) - 1; $GLOBALS['finds'] = ''; $loop = -1; $and = $once = $found = $found1 = $found2 = $bothfound = $search2also = 'no'; $count = 0; $speechmarks = ''; //test for AND but not two words that must be together (""): if ((strstr($search,' AND ')) and ($search[0] <> '"')) { $and = 'yes'; list ($word1, $word2, $word3) = explode (' ', $search); //remove AND $word1 = strtolower($word1); $word3 = strtolower($word3); if ($word1 == $word3) { $search = $word1; $and = 'no'; } else { $search1 = $word1; $search2 = $word3; while ($loop < $arrays) { $loop++; list($folder,$demo_path,$demo_name,$demo_notes,$demo_day,$demo_month,$demo_year) = explode('|',$col[$loop]); $field = $demo_name.'|'.$demo_notes; //preserve original text $fieldlow = strtolower($field); if ((strstr($fieldlow,$search1)) and (strstr($fieldlow,$search2))) { $found = $found1 = $found2 = $bothfound = 'yes'; getdetails($myurl,$folder,$demo_path,$demo_name,$demo_day,$demo_month,$demo_year); //word1 highlight($fieldlow,$field,$search1); //word2 $fieldlow = strtolower($GLOBALS['result']); //update field to include highlighted version from above highlight($fieldlow,$GLOBALS['result'],$search2); list($highlighted,$highlighted2) = explode('|',$GLOBALS['result']); if ($count >= $limit) { $hide = floor($count / $limit); $showpages = 'yes'; } $GLOBALS['finds'].='
  • '.$highlighted.' '.$highlighted2.' · '.$thedate.'
  • '; $count++; } } } } if (($and == 'no') and ($bothfound == 'no')) { $search = strtolower($search); $search1 = $search2 = ''; if (strstr($search,' ')) { list ($search1, $search2) = explode (' ', $search); if ($search2 == $search1) {//when both words are the same $search = $search1; //make search just first word $search1 = $search2 = ''; //destroy both words from split } } //test for space in search but not two words that must be together (""): if ((strstr($search,' ')) and ($search[0] <> '"')) { list ($search1, $search2) = explode (' ', $search); //search for two separate words while ($loop < $arrays) { $loop++; $search2also = 'no'; list($folder,$demo_path,$demo_name,$demo_notes,$demo_day,$demo_month,$demo_year) = explode('|',$col[$loop]); $field = $demo_name.'|'.$demo_notes; //preserve original text $fieldlow = strtolower($field); $fieldkept = $fieldlow; //preserve text without web code if (strstr($fieldlow,$search1)) { if (strstr($fieldlow,$search2)) {$search2also = $bothfound = 'yes';} $found = $found1 = 'yes'; getdetails($myurl,$folder,$demo_path,$demo_name,$demo_day,$demo_month,$demo_year); highlight($fieldlow,$field,$search1); if ($search2also <> 'yes') { //only output once when both words on same row list($highlighted,$highlighted2) = explode('|',$GLOBALS['result']); if ($count >= $limit) { $hide = floor($count / $limit); $showpages = 'yes'; } $GLOBALS['finds'].='
  • '.$highlighted.' '.$highlighted2.' · '.$thedate.'
  • '; $count++; } } if (strstr($fieldkept,$search2)) { //search on line without highlighting added $found = $found2 = 'yes'; getdetails($myurl,$folder,$demo_path,$demo_name,$demo_day,$demo_month,$demo_year); highlight($fieldlow,$GLOBALS['result'],$search2); if (($search2also == 'yes') or ($found2 == 'yes')) { list($highlighted,$highlighted2) = explode('|',$GLOBALS['result']); if ($count >= $limit) { $hide = floor($count / $limit); $showpages = 'yes'; } $GLOBALS['finds'].='
  • '.$highlighted.' '.$highlighted2.' · '.$thedate.'
  • '; $count++; } } } } else { //check if speech marks and remove them: if ($search[0] == '"') { $search = str_replace('"','',$search); $speechmarks = '\''; //for output later } if ($search <> '') { //do normal search while ($loop < $arrays) { $loop++; list($folder,$demo_path,$demo_name,$demo_notes,$demo_day,$demo_month,$demo_year) = explode('|',$col[$loop]); $field = $demo_name.'|'.$demo_notes; //preserve original text $fieldlow = strtolower($field); if (strstr($fieldlow,$search)) { $found = $found1 = 'yes'; getdetails($myurl,$folder,$demo_path,$demo_name,$demo_day,$demo_month,$demo_year); highlight($fieldlow,$field,$search); list($highlighted,$highlighted2) = explode('|',$GLOBALS['result']); if ($count >= $limit) { $hide = floor($count / $limit); $showpages = 'yes'; } $GLOBALS['finds'].='
  • '.$highlighted.' '.$highlighted2.' · '.$GLOBALS['thedate'].'
  • '; $count++; } } } else {exit('No usable search string found!');} } } //if ($and == 'no') if ($found == 'yes') { if ($count > 1) { $plural = 's'; } else { $plural = ''; } echo '

    \''.$speechmarks.$search.$speechmarks.'\' found '.$count.' demo'.$plural.':

      '.$GLOBALS['finds'].'
    '; if ($showpages == 'yes') { $pagecount = ceil($count / $limit); echo '

    Page: 1'; $pinkfloyd = 1; while ($pinkfloyd < $pagecount) { $pinkfloyd++; // if ($pinkfloyd > $buttons) {echo ' Last ('.$pagecount.')'; break;} echo ' '.$pinkfloyd.''; } echo '

    '; } } else { echo '

    \''.$speechmarks.$search.$speechmarks.'\' was not found.

    '; } echo '


    By Chris Hester 7th February 2012 | Updated: '.date('jS F Y', getlastmod()).' | About The Demo | Comments

    '; ?>