Location: PHPKode > scripts > Dict Translator > dict-translator/class.dicttranslator.php
<?
/**
 *	Klasa DictTranslator - t&#322;umaczenie polsko-angielski/angielsko-polski korzystaj&#261;c z dict.pl
 *
 *  @author  Arkadiusz Mali&#324;ski :: <hide@address.com>
 *  @version 0.1.0
 *
 */

define('DICT_ANY', 1);
define('DICT_ALL', 2);

class DictTranslator {
	
	private $_searched;
	private $_results = array();
	
	
/**
 *	funkcja przeprowadzaj&#261;ca t&#322;umaczenie
 *
 *	@param string		s&#322;owo b&#261;d&#378; s&#322;owa do t&#322;umaczenia
 *	@param int			typ t&#322;umaczenia; DICT_ANY - dowolne wyra&#380;enie, DICT_ALL - angielska sentencja
 *
 *	@return array		tablica zawieraj&#261;ca pary "polskie wyra&#380;enie" => "angielskie wyra&#380;enie"
 */
	function translate($words, $typ = DICT_ANY) {
		$arTmpResults = array();
		$this->_searched = urlencode($words);
		
		$_dictPage = curl_init();
		switch($typ) {
			case DICT_ALL:
				curl_setopt($_dictPage, CURLOPT_URL, "http://www.dict.pl/plen?words=".$this->_searched."&lang=PL");
				break;
			case DICT_ANY:
				curl_setopt($_dictPage, CURLOPT_URL, "http://www.dict.pl/plen?word=".$this->_searched."&lang=PL");
				break;
		}
		curl_setopt($_dictPage, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($_dictPage, CURLOPT_HEADER, 0);
		$tmpResult = preg_split('/\n/', curl_exec($_dictPage));
		curl_close($_dictPage);

		foreach($tmpResult as $line) {
			if(preg_match("/<!--m-->/", $line))
				array_push($arTmpResults, strip_tags($line));
		}
		for($i=0; $i<count($arTmpResults); $i=$i+2) {
			$this->_results = array_merge($this->_results, array($arTmpResults[$i]=>$arTmpResults[$i+1]));
		}
		
		return $this->_results;
	}
}

?>
Return current item: Dict Translator