function rem_Entities($str) { if (substr_count($str, '&') && substr_count($str, ';')) { $amp_pos = strpos($str, '&'); $semi_pos = strpos($str, ';'); if ($semi_pos > $amp_pos) { $tmp = substr($str, 0, $amp_pos); $tmp = $tmp . substr($str, $semi_pos + 1, strlen($str)); $str = $tmp; if (substr_count($str, '&') && substr_count($str, ';')) { $str = rem_Entities($tmp); } } } return $str; }
function checkSpelling($sword) { /** SPELL CHECK FROM DATABASE * */ $spellq = "SELECT corrected FROM spelling WHERE word_in = '{$sword}'"; $spellresult = mysql_query($spellq) or trigger_error(mysql_error() . " in {$spqellq}", E_USER_ERROR); if (mysql_num_rows($spellresult) > 0) { $row = mysql_fetch_row($spellresult); $corrected = $row[0]; return $corrected; } $wordnik = ''; $req = rawurlencode($sword); $c = count(explode(" ", $sword)); if ($c > 1) { /** SPELL CHECK WORDNIK * */ $url = "API"; $response = httpGet($url); $xmlObj = simplexml_load_string($response); $arrXml = objectsIntoArray($xmlObj); if (isset($arrXml['suggestions']['suggestion'])) { $wordnik = $arrXml['suggestions']['suggestion']; } } if ($wordnik == '') { /** SPELL CHECK GOOGLE* */ $url = "API"; $text = httpGet($url); $text = strip_tags($text); $text = rem_Entities($text); $pos = stripos($text, 'Did you mean:'); if ($pos !== false) { $text = substr($text, $pos); $pos = stripos($text, ' '); $text = left($text, $pos); $text = substr($text, 14); $req = $text; } else { $pos = stripos($text, 'Showing results for'); if ($pos !== false) { $text = substr($text, $pos); $pos = stripos($text, '.'); $text = left($text, $pos); $text = trim(substr($text, 19)); $req = $text; } else { $req = $sword; } } } $req = urldecode($req); $spellq = "INSERT INTO spelling VALUES ('{$sword}','{$req}')"; mysql_query($spellq) or trigger_error(mysql_error() . " in {$spqellq}", E_USER_ERROR); return $req; }
<?php $weather_req = urlencode($word); $url = 'API'; $content = httpGet($url); $tt = stripos($content, "Add to iGoogle"); if ($tt !== false) { $content = substr($content, $tt + 14); $tt = stripos($content, "<div align=center"); if ($tt !== false) { $content = left($content, $tt); $content = str_ireplace("<b>", " ", $content); $content = str_ireplace("<br>", " \n", $content); $content = strip_tags($content); $content = rem_Entities($content); $content = utf8_encode($content); $content = str_replace("°C", " Degree Celsius \n", "{$content}"); while (stripos($content, " ") !== false) { $content = str_ireplace(" ", " ", $content); } $content = trim($content); $word = ucwords($word); $weather_return = $word . " right now: " . $content; } else { $weather_return = ''; } } else { $weather_return = ''; }