Skip to content

Instantly share code, notes, and snippets.

@flrngel
Created November 21, 2013 02:34
Show Gist options
  • Save flrngel/7575186 to your computer and use it in GitHub Desktop.
Save flrngel/7575186 to your computer and use it in GitHub Desktop.
elegant full address search on UTF-8
function fullSearch($array){
$limit=intval($array['limit'])==0?100:intval($array['limit']);
$address=$array['address'];
// process for elegant searching - by `surplus` flrngel
$na=array();
$split= explode(" ",$address);
$newstr=null;
foreach($split as $key=>$val){
preg_match_all('/./u',$val,$hangul_cut);
$hangul_cut=$hangul_cut[0];
$newstr.=$val;
if( in_array($hangul_cut[count($hangul_cut)-1],array('시','도','읍','면','동','군','구')) ){
$na[]=$newstr;
$newstr=null;
}
}
if( $newstr ) $na[]=$newstr;
$address=join($na," ");
// elegant searching end
$sql="select * from Postcode where full like '%$address%' limit $limit";
$res=$this->db->query($sql)->fetch_all_objects();
return $res;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment