DeTypo in PHP
Sometimes we need to detect mistypes ![]()
We can use google-search to make sure if given word is a mistype, here my solution:
- if($_GET['key']!=''){
- $key=$_GET['key'];
- $s=GetData('http://www.google.com/search?q='.urlencode($key));
- if(strstr($s, '&spell=1 class=p><b><i>')){
- $s=substr($s, strpos($s, '&spell=1 class=p><b><i>')+strlen('&spell=1 class=p><b><i>'));
- $s=substr($s, 0, strpos($s, '</a>'));
- $key=strip_tags($s);
- }
- echo $key;
- }
- function GetData($url){
- $ch=curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_TIMEOUT, 15);
- $out=curl_exec($ch);
- curl_close($ch);
- return $out;
- }
Using:
http://site.com/detypo.php?key=wordl
Tags: SEO, PHP, detypo, mistype, php