"; //echo "Daughter: ". $femalestr; $term = $malestr; // END OF STRING REPLACEMENT // Clean up by removing unwanted characters $term = ereg_replace("[^ 0-9a-zA-Z]", " ", $term); $term = trim($term); //remove space from the beginning and end // Remove multiple adjacent spaces while (strstr($term, " ")) { $term = str_replace(" ", " ", $term); } if(isset($_GET['page'])) { $page = intval($_GET["page"]); if($page<=0) $page = 1; $reload = "search.html"; }else{ $page = 1; $reload = "search.html"; } require "phpspellcheck/include.php" ; function suggestionslink ($input){ if (empty($input)) {return "";} //if ((strlen($input)) == 0){return "";} //if((trim($input))==""){return "";} $spellcheckObject = new PHPSpellCheck(); $spellcheckObject -> LicenceKey = "TRIAL"; $spellcheckObject -> DictionaryPath = ("phpspellcheck/dictionaries/"); $spellcheckObject -> LoadDictionary("Bahasa Malaysia") ; //OPTIONAL// $spellcheckObject -> LoadCustomDictionary("custom.txt"); $suggestionText = $spellcheckObject ->didYouMean($input); if($suggestionText==""){return "";} return $suggestionText; } ?> Search <?php echo ucwords(strtolower($term)); ?>

Results:

'. suggestionslink($suggest[0]) .' ?'; echo '
'; echo '
'; } //end suggest // remove spaces and other character $term = preg_replace('/[^a-z0-9]+\Z/i', '', $term); $term = rtrim($term); // Add + sign into each keyword $str = $term; $symbol = '+'; $newString = $symbol . str_replace(' ', " $symbol", $str); //echo $newString; //NON FULL TEXT //SELECT *, ( (value_column LIKE '%rusten%') + (value_column LIKE '%dagen%') + (value_column LIKE '%bezoek%') + (value_column LIKE //'%moeten%') ) as count_words //FROM data_table //WHERE (value_column LIKE '%dagen%' OR value_column LIKE '%rusten%' OR value_column LIKE '%bezoek%' OR value_column LIKE '%moeten%') //ORDER BY count_words DESC //FULL TEXT //SELECT * FROM data_table //WHERE MATCH(value_column) AGAINST('+dagen +rusten +bezoek +moeten' IN BOOLEAN MODE) //ORDER BY MATCH(value_column) AGAINST('+dagen +rusten +bezoek +moeten' IN BOOLEAN MODE) DESC; //select the table //FULL TEXT $newString = mysql_real_escape_string($newString); // makes sure nobody uses SQL injection $result = mysql_query("select * from malaysia_postcode where match (location, categories, post_office, state_name, other_name) against ('%$newString%' IN BOOLEAN MODE) ORDER BY MATCH (location, categories, post_office, state_name, other_name) AGAINST('%$newString%' IN BOOLEAN MODE) DESC"); //NON FULL TEXT //select the table //$result = mysql_query("select * from malaysia_postcode where location like '%$term%' OR //post_office like '%$term%' OR state_name like '%$term%'"); // total listing $tcount = mysql_num_rows($result); // total pages $tpages = ($tcount) ? ceil($tcount/$rpp) : 1; // total pages, last page number $count = 0; $i = ($page-1)*$rpp; // IF NO RESULT, Check total words if (!mysql_num_rows($result)) { // count words $txt = trim($term); $words = explode( " ", $txt); // $words[0] = "oneword", $words[1] = "secondword" // Query 3 perkataan sahaja if (count($words) == 3) { //suggest $query = $term; $suggest = preg_split('/(?=[0-9])/', $query); // If got suggestion, print out if (suggestionslink($suggest[0]) ) { echo 'No Results found. Did you mean '. suggestionslink($suggest[0]) .' '. suggestionslink($suggest[1]) .' '. suggestionslink($suggest[2]) .' ?'; echo '
'; echo '
'; // Add + sign into each keyword $str = $term; $symbol = '+'; $newString = $symbol . str_replace(' ', " $symbol", $str); //echo $newString; $term = ''. $suggest[0] .' '. $suggest[1] .''; $newString = mysql_real_escape_string($newString); // makes sure nobody uses SQL injection //select the table //full text search $result = mysql_query("select * from malaysia_postcode where match (location, categories, post_office, state_name, other_name) against ('%$newString%' IN BOOLEAN MODE) ORDER BY MATCH (location, categories, post_office, state_name, other_name) AGAINST('%$newString%' IN BOOLEAN MODE) DESC"); // total listing $tcount = mysql_num_rows($result); // total pages $tpages = ($tcount) ? ceil($tcount/$rpp) : 1; // total pages, last page number $count = 0; $i = ($page-1)*$rpp; echo paginate_search($reload, $page, $term, $tpages, $adjacents); while (($count < $rpp) && ($i < $tcount)) { mysql_data_seek($result,$i); $row = mysql_fetch_array($result); // highlight $keywords = $term; //Keyword to highlight. $searchresults = $row['location']; //Result of search. $highlight = preg_replace("|($keywords)|Ui", "$1", $searchresults); // end higlight //remove space from the beginning and end $cleanlocation = trim($row['location']); // Replace single spaces with a URL friendly plus sign $cleanlocation = str_replace(" ", "+", $cleanlocation); $cleanlocation = strtolower($cleanlocation); // make state lowercase $cleanstate = strtolower($row['state_code']); echo'

'.$row['location'].'

'; echo'
'; echo''; echo''; //echo 'ID: '.$row['postcode']; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo''; echo'
Location Name:'.$highlight.'
State Name:'.$row['state_name'].'
Postal Code:'.$row['postcode'].'
'; echo'
'; echo'
'; echo ''; $i++; $count++; } // else if no suggestion }else{ echo "No Results found. But we refined your search. "; echo '
'; echo '
'; $query = $term; // strip last word (FIRST SECOND THIRD) $newquery= preg_replace('/\W\w+\s*(\W*)$/', '$1', $query); // Add + sign into each keyword $str = $newquery; $symbol = '+'; $newString = $symbol . str_replace(' ', " $symbol", $str); //echo $newString; $term = ''. $suggest[0] .' '. $suggest[1] .''; $newString = mysql_real_escape_string($newString); // makes sure nobody uses SQL injection //select the table //full text search $result = mysql_query("select * from malaysia_postcode where match (location, categories, post_office, state_name, other_name) against ('%$newString%' IN BOOLEAN MODE) ORDER BY MATCH (location, categories, post_office, state_name, other_name) AGAINST('%$newString%' IN BOOLEAN MODE) DESC"); // total listing $tcount = mysql_num_rows($result); $tpages = ($tcount) ? ceil($tcount/$rpp) : 1; // total pages, last page number $count = 0; $i = ($page-1)*$rpp; echo paginate_search($reload, $page, $term, $tpages, $adjacents); while (($count < $rpp) && ($i < $tcount)) { mysql_data_seek($result,$i); $row = mysql_fetch_array($result); // highlight $keywords = $term; //Keyword to highlight. $searchresults = $row['location']; //Result of search. $highlight = preg_replace("|($keywords)|Ui", "$1", $searchresults); // end higlight //remove space from the beginning and end $cleanlocation = trim($row['location']); // Replace single spaces with a URL friendly plus sign $cleanlocation = str_replace(" ", "+", $cleanlocation); $cleanlocation = strtolower($cleanlocation); // Make state lowercase $cleanstate = strtolower($row['state_code']); echo'

'.$row['location'].'

'; echo'
'; echo''; echo''; //echo 'ID: '.$row['postcode']; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo''; echo'
Location Name:'.$highlight.'
State Name:'.$row['state_name'].'
Postal Code:'.$row['postcode'].'
'; echo'
'; echo'
'; echo ''; $i++; $count++; } if ( isset($term)) { $term = mysql_real_escape_string($term); // makes sure nobody uses SQL injection // insert into QUERY SEARCH FOR RECENT $sql = 'INSERT INTO query '.'(keyword,type,id) '.'VALUES ( "'.$term.'","NF", "" )'; mysql_select_db('poskod_portal'); $result = mysql_query( $sql, $dbh ); // end QUERY SEARCH FOR RECENT }; } echo paginate_search($reload, $page, $term, $tpages, $adjacents); // Query lebih dari 3 perkataan }elseif (count($words) > 3) { $query = $term; $value = $query; $tokens = explode(" ", $value); echo 'No results found. Did you mean '. $tokens[0] .' '. $tokens[1] .' or '. $tokens[0] .' '. $tokens[1] .' '. $tokens[2] .' ?'; echo '
'; echo '
'; $term = $tokens[0] .' '. $tokens[1]; // Add + sign into each keyword $str = $term; $symbol = '+'; $newString = $symbol . str_replace(' ', " $symbol", $str); //echo $newString; $newString = mysql_real_escape_string($newString); // makes sure nobody uses SQL injection //select the table $result = mysql_query("select * from malaysia_postcode where match (location, post_office, categories, state_name, other_name) against ('%$newString%' IN BOOLEAN MODE) ORDER BY MATCH (location, categories, post_office, state_name, other_name) AGAINST('%$newString%' IN BOOLEAN MODE) DESC"); // total listing $tcount = mysql_num_rows($result); // total pages $tpages = ($tcount) ? ceil($tcount/$rpp) : 1; // total pages, last page number $count = 0; $i = ($page-1)*$rpp; echo paginate_search($reload, $page, $term, $tpages, $adjacents); while (($count < $rpp) && ($i < $tcount)) { mysql_data_seek($result,$i); $row = mysql_fetch_array($result); // highlight $keywords = $term; //Keyword to highlight. $searchresults = $row['location']; //Result of search. $highlight = preg_replace("|($keywords)|Ui", "$1", $searchresults); // end higlight //remove space from the beginning and end $cleanlocation = trim($row['location']); // Replace single spaces with a URL friendly plus sign $cleanlocation = str_replace(" ", "+", $cleanlocation); $cleanlocation = strtolower($cleanlocation); // Make state lowercase $cleanstate = strtolower($row['state_code']); echo'

'.$row['location'].'

'; echo'
'; echo''; echo''; //echo 'ID: '.$row['postcode']; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo''; echo'
Location Name:'.$highlight.'
State Name:'.$row['state_name'].'
Postal Code:'.$row['postcode'].'
'; echo'
'; echo '
'; echo ''; $i++; $count++; } $term = mysql_real_escape_string($term); // makes sure nobody uses SQL injection // if there is a keyword, insert to database as a recent search if (isset($term)) { // insert into QUERY SEARCH FOR RECENT $sql = 'INSERT INTO query '. '(keyword,id) '. 'VALUES ( "'.$term.'","" )'; mysql_select_db('poskod_portal'); $result = mysql_query( $sql, $dbh ); // end QUERY SEARCH FOR RECENT }; echo paginate_search($reload, $page, $term, $tpages, $adjacents); // Query 1 atau 2 perkataan }else{ if (!mysql_num_rows($result)) { // Single work Query // Remove everything after the first comma $query = $term; $suggest = preg_replace('/^([^,]*).*$/', '$1', $query); if (suggestionslink($suggest)) { echo 'No results found. Did you mean '. suggestionslink($suggest) .' ?'; if (isset($term)) { $term = mysql_real_escape_string($term); // makes sure nobody uses SQL injection // insert into QUERY SEARCH FOR RECENT (FBS = FOUND BUT SUGGESTED) $sql = 'INSERT INTO query '.'(keyword,type,id) '.'VALUES ( "'.$term.'","FBS","" )'; mysql_select_db('poskod_portal'); $result = mysql_query( $sql, $dbh ); // insert into QUERY SEARCH FOR RECENT (FBS = FOUND BUT SUGGESTED) }; }else{ echo 'No results found.'; if (isset($term)) { $term = mysql_real_escape_string($term); // makes sure nobody uses SQL injection // insert into QUERY SEARCH FOR RECENT (NF = NOT FOUND) $sql = 'INSERT INTO query '.'(keyword,type,id) '.'VALUES ( "'.$term.'","NF","" )'; mysql_select_db('poskod_portal'); $result = mysql_query( $sql, $dbh ); // insert into QUERY SEARCH FOR RECENT (NF = NOT FOUND }; } echo '
'; echo '
'; }else{ echo 'Sorry. No results found.'; echo '
'; echo '
'; } $iterm = suggestionslink($suggest); $iterm = mysql_real_escape_string($iterm); // makes sure nobody uses SQL injection //select the table $result = mysql_query("select * from malaysia_postcode where location like '%$iterm%'"); // total listing $tcount = mysql_num_rows($result); // total pages $tpages = ($tcount) ? ceil($tcount/$rpp) : 1; // total pages, last page number $count = 0; $i = ($page-1)*$rpp; echo paginate_search($reload, $page, $iterm, $tpages, $adjacents); while (($count < $rpp) && ($i < $tcount)) { mysql_data_seek($result,$i); $row = mysql_fetch_array($result); // highlight $keywords = $iterm; //Keyword to highlight. $searchresults = $row['location']; //Result of search. $highlight = preg_replace("|($keywords)|Ui", "$1", $searchresults); // end higlight //remove space from the beginning and end $cleanlocation = trim($row['location']); // Replace single spaces with a URL friendly plus sign $cleanlocation = str_replace(" ", "+", $cleanlocation); $cleanlocation = strtolower($cleanlocation); // Make state lowercase $cleanstate = strtolower($row['state_code']); echo'

'.$row['location'].'

'; echo'
'; echo''; echo''; //echo 'ID: '.$row['postcode']; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo''; echo'
Location Name:'.$highlight.'
State Name:'.$row['state_name'].'
Postal Code:'.$row['postcode'].'
'; echo'
'; echo '
'; echo ''; $i++; $count++; } } // End Query 1 atau 2 perkataan }else{ //while ($row = mysql_fetch_array($result)){ echo paginate_search($reload, $page, $term, $tpages, $adjacents); while (($count < $rpp) && ($i < $tcount)) { mysql_data_seek($result,$i); $row = mysql_fetch_array($result); // highlight $keywords = $term; //Keyword to highlight. $searchresults = $row['location']; //Result of search. $highlight = preg_replace("|($keywords)|Ui", "$1", $searchresults); // end higlight //remove space from the beginning and end $cleanlocation = trim($row['location']); // Replace single spaces with a URL friendly plus sign $cleanlocation = str_replace(" ", "+", $cleanlocation); $cleanlocation = strtolower($cleanlocation); // Make state lowercase $cleanstate = strtolower($row['state_code']); echo'

'.$row['location'].'

'; echo'
'; echo''; echo''; //echo 'ID: '.$row['postcode']; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo''; echo'
Location Name:'.$highlight.'
State Name:'.$row['state_name'].'
Postal Code:'.$row['postcode'].'
'; echo'
'; echo '
'; echo ''; $i++; $count++; } $Tag = 'My Name is Gaurav'; $kira = str_word_count($Tag); //echo $kira; $term = mysql_real_escape_string($term); // makes sure nobody uses SQL injection // QUERY SEARCH FOR RECENT (1 Query) if (isset($term)) { // insert into QUERY SEARCH FOR RECENT (For 1 Query with more than 3 words) $sql = 'INSERT INTO query '. '(keyword,id) '. 'VALUES ( "'.$term.'","" )'; mysql_select_db('poskod_portal'); $result = mysql_query( $sql, $dbh ); // end QUERY SEARCH FOR RECENT }; echo paginate_search($reload, $page, $term, $tpages, $adjacents); } // else if query is number only }else{ // check number length. 5 digits $num_length = strlen((string)$term); if($num_length == 5) { $term = mysql_real_escape_string($term); // makes sure nobody uses SQL injection //select the table $result = mysql_query("select * from malaysia_postcode where postcode like '%$term%'"); // total listing $tcount = mysql_num_rows($result); // total pages $tpages = ($tcount) ? ceil($tcount/$rpp) : 1; // total pages, last page number $count = 0; $i = ($page-1)*$rpp; if (!mysql_num_rows($result)) { echo 'No results found.'; }else{ //while ($row = mysql_fetch_array($result)){ echo paginate_search($reload, $page, $term, $tpages, $adjacents); while (($count < $rpp) && ($i < $tcount)) { mysql_data_seek($result,$i); $row = mysql_fetch_array($result); // highlight $keywords = $term; //Keyword to highlight. $searchresults = $row['location']; //Result of search. $highlight = preg_replace("|($keywords)|Ui", "$1", $searchresults); // end higlight //remove space from the beginning and end $cleanlocation = trim($row['location']); // Replace single spaces with a URL friendly plus sign $cleanlocation = str_replace(" ", "+", $cleanlocation); $cleanlocation = strtolower($cleanlocation); // Make state lowercase $cleanstate = strtolower($row['state_code']); echo'

'.$row['location'].'

'; echo'
'; echo''; echo''; //echo 'ID: '.$row['postcode']; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo''; echo'
Location sName:'.$highlight.'
State Name:'.$row['state_name'].'
Postal Code:'.$row['postcode'].'
'; echo'
'; echo '
'; echo ''; $i++; $count++; } $term = mysql_real_escape_string($term); // makes sure nobody uses SQL injection if ( isset($term)) { // insert into QUERY SEARCH FOR RECENT $sql = 'INSERT INTO query '. '(keyword,id) '. 'VALUES ( "'.$term.'","" )'; mysql_select_db('poskod_portal'); $result = mysql_query( $sql, $dbh ); // end QUERY SEARCH FOR RECENT }; echo paginate_search($reload, $page, $term, $tpages, $adjacents); } } else { echo "Sorry please enter a valid postcode number."; $term = mysql_real_escape_string($term); // makes sure nobody uses SQL injection if ( isset($term)) { // insert into QUERY SEARCH FOR RECENT $sql = 'INSERT INTO query '. '(keyword,id) '. 'VALUES ( "'.$term.'","" )'; mysql_select_db('poskod_portal'); $result = mysql_query( $sql, $dbh ); // end QUERY SEARCH FOR RECENT }; } } ?>