Search

'.$output.'

Home

© Adam Newbold

'; } if(isset($_REQUEST['q']) && ($_REQUEST['q'] !== '')) { $q = strip_tags($_REQUEST['q']); $connection = mysql_connect('content.newbold.name', 'content', '') or die('Could not connect: ' . mysql_error()); mysql_select_db('content') or die('Could not select database'); $query = 'SELECT * FROM content WHERE page like "%'.$q.'%" OR title like "%'.$q.'%" OR content like "%'.$q.'%" ORDER BY modified DESC'; $result = mysql_query($query) or die('Query failed: ' . mysql_error()); $count = mysql_num_rows($result); if($count == 0) $rs = ' did not match any items.'; if($count == 1) $rs = ' matched one item.'; if($count > 1) $rs = ' matched '.$count.' items.'; if($count >= 1) { $output = '

Your search for '.$q.''.$rs.'

'; while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) { $found = array(); $content = strip_tags(SmartyPants(Markdown($line['content']))); $cr = explode(" ", $content); foreach($cr as $k=>$v) if(stristr($v, $q) !== false) $found[] = $k; if(count($found) !== 0) { $offset = 10; if($found[0] < $offset) { $start = 0; $p1 = ''; } else { $start = $found[0] - $offset; $p1 = '...'; } if($found[0]+$offset >= count($cr)) { $p2 = ''; } else { $p2 = '...'; } $cr[$found[0]] = ''.$cr[$found[0]].''; $context = array_slice($cr, $start, $offset*2); $context = $p1.implode(" ", $context).$p2.'
'; } $output .= '

'.$line['title'].'
'.$context.'newbold.name/'.$line['page'].'/  -  '.date("F j, Y", $line['modified']).'

'; } } else $output = '

Your search for '.$q.''.$rs.'

'; mysql_close($connection); } else $output .= '

You can search the content on this site using the form above.

'; html($output); ?>