<?php class FanyiAction extends Action { public function _empty(){ header("HTTP/1.0 404 Not Found"); $this->display("Public:404"); } public function index() { $User = A("Index"); $User->head(); $User->right(); $User->footer(); $this->display(); } public function fanyi() { $value=$_POST['value']; $from="auto"; $to="auto"; $value_code=urlencode($value); $appid="xxxxxxxx";//这里填写你在百度上申请的API key $languageurl = "http://openapi.baidu.com/public/2.0/bmt/translate?client_id=" . $appid ."&q=" .$value_code. "&from=".$from."&to=".$to; $text=json_decode($this->language_text($languageurl)); $text = $text->trans_result; $rs=$text[0]->dst; $this->assign('value',$value); $this->assign('rs',$rs); $User = A("Index"); $User->head(); $User->right(); $User->footer(); $this->display('index'); } Baidu Translation は、Baidu がリリースしたオンライン翻訳サービスで、インターネット データ リソースと自然言語処理テクノロジーの利点を利用して、ユーザーが言語のギャップを埋め、情報やサービスを便利かつ迅速に入手できるように支援します。 Baidu 翻訳は、中国語、英語、日本語、韓国語、スペイン語、タイ語、フランス語、アラビア語、ポルトガル語、ロシア語、ドイツ語、イタリア語、オランダ語、ギリシャ語英語を含む、世界中で人気のある 28 言語への翻訳をサポートしています。 、エストニア語、ブルガリア語、ポーランド語、デンマーク語、フィンランド語、チェコ語、ルーマニア語、スウェーデン語、スロベニア語、ハンガリー語、ベトナム語、広東語、古典中国語、繁体中国語、756 の翻訳方向をカバーしています。 「世界は複雑です。Baidu はあなたのことをよく理解しています。」 Baidu Translate は Web 版やモバイル APP などの複数の製品形態を持ち、さらに開発者向けにオープン クラウド インターフェイス サービスも提供しており、数億件の回答に対応しています。毎日翻訳依頼が増えております。テキスト翻訳に加え、ユーザーの多様な翻訳ニーズに基づき、Webページ翻訳、オンライン定義、膨大な例文、権威辞書、オフライン翻訳、音声翻訳、会話翻訳、実用音声翻訳、写真翻訳などの機能を提供しています。 、ユーザーはあらゆる翻訳体験を楽しむことができます。 2013 年 2 月 28 日、百度翻訳は携帯電話の使用シナリオに基づいて Android モバイル クライアントを正式に開始し、2013 年 3 月 7 日には iOS モバイル クライアントを正式にリリースしました。 2015年5月、世界初のインターネットNMTオンライン製品であるニューラルネットワーク翻訳(NMT)システムがリリースされました。 2015年6月には、中国語、英語、日本語、韓国語などの多言語に対応した携帯電話向けオフラインNMTシステムをリリースした。 2016 年 7 月 5 日、Baidu 人間翻訳が正式にリリースされ、ユーザーに有料で正確な人間による翻訳サービスを提供し、さまざまなシナリオにおけるユーザーの翻訳ニーズをより包括的に満たすことに取り組んでいます。
<?php //功能:生成缩略图 class CreatMiniature { //公共变量 var $srcFile = ""; //原图 var $echoType; //输出图片类型,link--不保存为文件;file--保存为文件 var $im = ""; //临时变量 var $srcW = ""; //原图宽 var $srcH = ""; //原图高 //设置变量及初始化 function SetVar($srcFile, $echoType) { if (!file_exists($srcFile)) { echo '源图片文件不存在!'; exit(); } $this->srcFile = $srcFile; $this->echoType = $echoType; $info = ""; $data = GetImageSize($this->srcFile, $info); switch ($data[2]) { case 1: if (!function_exists("imagecreatefromgif")) { echo "你的GD库不能使用GIF格式的图片,请使用Jpeg或PNG格式!返回"; exit(); }サムネイル生成関数 (画像形式: gif、jpeg、png、bmp をサポート) * @author ruxing.li * @param string $src ソース画像パス * @param int $width サムネイルの幅 (高さのみを指定した場合は等角スケーリングを行います) * @param int $width サムネイルの高さ(幅のみを指定した場合は等角スケーリングを行います) * @param string $filename 保存パス (指定しない場合はブラウザに直接出力) * @return bool
<?php class Student { var $str_Name; var $str_Sex; var $int_Id; var $int_English; var $int_maths; function Input ( $Name, $Sex, $Id, $English, $Maths) { $this->str_Name=$Name; $this->str_Sex =$Sex; $this->int_Id =$Id; $this->int_English=$English; $this->int_Maths=$Maths; } function ShowInfo() { echo ("姓名:$this->str_Name<br> "); echo ("性别:$this->str_Sex <br> "); echo ("学号:$this->int_Id <br> "); echo ("英语成绩:$this->int_English <br> "); echo ("数学成绩:$this->int_Maths <br> "); } } $Wing = new Student; $Wing->Input ("Wing","男",33,95,87); $Paladin = new Student; $Paladin->Input ("paladin","女",38,58,59.5); $Wing->ShowInfo(); $Paladin->ShowInfo(); ?> 名前、性別、生徒番号、英語のスコア、数学のスコアなどを含む人間のクラスを定義します。
<?php class cache { var $cacheRoot = "./cache/"; var $cacheLimitTime = 3; var $cacheFileName = ""; var $cacheFileExt = "php"; function cache( $cacheLimitTime ) { if( intval( $cacheLimitTime ) ) $this->cacheLimitTime = $cacheLimitTime; $this->cacheFileName = $this->getCacheFileName(); ob_start(); } function cacheCheck(){ if( file_exists( $this->cacheFileName ) ) { $cTime = $this->getFileCreateTime( $this->cacheFileName ); if( $cTime + $this->cacheLimitTime > time() ) { echo file_get_contents( $this->cacheFileName ); ob_end_flush(); exit; } } return false; } 一般的に、キャッシュの目的は、アクセスを高速化するためにデータを 1 か所に置くことです。メモリが最速であることに疑いの余地はありませんが、数百 M のデータをメモリに保存できるでしょうか? これは当てはまりません。実際には、もちろん、サーバー キャッシュに一時的に配置される場合もあります。たとえば、ob_start() キャッシュ ページがオンになっている場合、ページの出力が完了するまで、ページ コンテンツはファイル ヘッダーを送信する前にメモリにキャッシュされます。自動的にクリアされるか、ob_get_contents の戻りを待機します [または ob_end_clean によってクリアされます。これは静的ページの生成によく使用でき、テンプレートに適切に反映できます
<?php class fileoperate { var $path; var $name; var $result; function creat_file($path,$name) { $filename=$path.$name; if (file_exists($filename)) { echo "文件已经存在,请换个文件名"; } else { if (file_exists($path)) { touch($name); rename($name,$filename); echo "文件建立成功 </br>"; } else{ echo "目录不存在,请检查"; } } } 指定したパスに指定したファイルを作成します * @param string $path (ファイル名とサフィックスを含める必要があります) * @param boolean $over_write file * @param int $time 時間を設定します。デフォルトは現在のシステム時間です * @param int $atime アクセス時間を設定します。デフォルトは現在のシステム時刻です。
<?php //打印上一个session; //echo "上一个session:<b>".$_SESSION["authnum_session"]."</b><br>"; $validate=""; if(isset($_POST["validate"])){ $validate=$_POST["validate"]; echo "您刚才输入的是:".$_POST["validate"]."<br>状态:"; if($validate!=$_SESSION["authnum_session"]){ //判断session值与用户输入的验证码是否一致; echo "<font color=red>输入有误</font>"; }else{ echo "<font color=green>通过验证</font>"; } }まず完全な検証ページを作成し、次にそのページでセッションを開きます。毎回新しいセッション値を取得できるように、セッションを削除します。 Seesionの効果は良くて、とても便利です
<?PHP header("Content-type: text/html; charset=utf-8"); $link = mysql_connect('localhost','root','eric') or die(mysql_error()); mysql_select_db('sortclass',$link); class SortClass{ var $data = array(); var $child = array(-1=>array()); var $layer = array(-1=>-1); var $parent = array(); var $link; var $table; function SortClass($link, $table){ $this->setNode(0, -1, '顶极节点'); $this->link = $link; $this->table = $table; $node = array(); $results = mysql_query('select * from '.$this->table.'',$this->link); while($node = mysql_fetch_assoc($results)){ $this->setNode($node['cid'],$node['pid'],$node['cname']); } }これは、再帰的と非再帰的の 2 つのメソッドを備えた PHP 無限分割の実装ライブラリです。必要な友達はダウンロードして使用できます。
<?php class Parser { private $_tpl; public function __construct($_tplFile) { if (! $this->_tpl = file_get_contents($_tplFile)) { exit('ERROR:模版文件读取错误'); } } private function parvar() { $_patten = '/<!--\s+\{$([\w]+)\}\s+-->/'; if (preg_match($_patten,$this->_tpl)) { $this->_tpl = preg_replace($_patten, "<?php echo $this->_vars[''];?>",$this->_tpl); } } private function parif(){ $_pattenif = '/<!--\s+\{if\s+$([\w]+)\}\s+-->/'; $_pattenElse = '/<!--\s+\{else\}\s+-->/'; $_pattenEndif = '/<!--\s+\{\/if\}\s+-->/'; if (preg_match($_pattenif,$this->_tpl)) { if (preg_match($_pattenEndif,$this->_tpl)) { $this->_tpl = preg_replace($_pattenif,"<?php if ($this->_vars['']){?>",$this->_tpl); $this->_tpl = preg_replace($_pattenEndif,"<?php } ?>",$this->_tpl); if (preg_match($_pattenElse,$this->_tpl)) { $this->_tpl = preg_replace($_pattenElse,"<?php }else{?>",$this->_tpl); } }else{ echo 'ERROR:IF语句没有关闭!'; } } }テンプレート ファイルの内容を受け取った後、メソッドを構築し、テンプレート ファイルの内容を取得して解析し、通常の変数を使用して IF ステートメントを解析し、テンプレート ファイルを解析してコンパイル済みファイルを生成します。
<?php class AlipayNotify { var $https_verify_url = 'https://mapi.alipay.com/gateway.do?service=notify_verify&'; var $http_verify_url = 'http://notify.alipay.com/trade/notify_query.do?'; var $alipay_config; function __construct($alipay_config){ $this->alipay_config = $alipay_config; } function AlipayNotify($alipay_config) { $this->__construct($alipay_config); } function verifyNotify(){ if(empty($_POST)) {//判断POST来的数组是否为空 return false; }これは、HTTPS メッセージの形式でアドレスを確認し、notify_url を使用して、メッセージが Alipay から送信された正当なメッセージであるかどうかを確認し、POST からの配列が空であるかどうかを判断し、Alipay の ATN 結果を取得します。リモートサーバー (Alipay によって送信されたメッセージであるかどうかを確認します)。
<?php class mysafe{ public $logname; public $isshwomsg; function __construct(){ set_error_handler('MyError',E_ALL); //----- } function MyError($errno, $errstr, $errfile, $errline){ echo "<b>Error number:</b> [$errno],error on line $errline in $errfile<br />"; exit; } function wlog($logs){ if(empty($logname)){ $this->logname=$_SERVER["DOCUMENT_ROOT"]."/log.htm"; } $Ts=fopen($this->logname,"a+"); fputs($Ts,$logs."\r\n"); fclose($Ts); } function showmsg($msg='',$flag=false){ $this->isshwomsg=empty($this->isshwomsg) ? false : true; if ($this->isshwomsg) { echo '<br />--------------------------------------<br />'; echo $msg; echo '<br />--------------------------------------<br />'; if ($flag) exit; }これは PHP パラメータおよびデータ フィルタリング クラスです。データ セキュリティのため、フィルタリングされたデータは使用する前に使用する必要があります。
<?php class qqlogin{ public $app_id; public $app_key; public $callback; public $code; public $state; public function __construct($app_id,$app_key,$callback){ $this->code = isset($_REQUEST['code'])? $_REQUEST['code'] : ''; $this->state = isset($_REQUEST['state'])? $_REQUEST['state'] : ''; $this->app_id = $app_id; $this->app_key = $app_key; $this->callback = $callback; } public function get_token(){ $url = "https://graph.qq.com/oauth2.0/token?grant_type=authorization_code&client_id=".$this->app_id."&client_secret=".$this->app_key."&code=".$this->code."&redirect_uri=".urlencode($this->callback); $str = $this->visit_url($url); parse_str($str,$arr); return $arr; }これは QQ ログイン クラスであり、QQ ログイン インターフェイス、php-qq ログイン クラスに使用されます。このクラスはカプセル化されており、QQ ログイン コールバック ページに使用されます。 app_id、app_key、callbackQQ アクセス プロセスを理解するには、QQ インターネット ドキュメントにアクセスする必要があります。このタイプはコールバック関数のみをカプセル化します。 URL アドレスをリクエストし、戻り文字列を取得し、その文字列を json_decode できる形式に変換し、curl を通じてページの戻り値を取得します。
<?php class Image { private $info; private $image; public $type; public function __construct($src) { $this->info=getimagesize($src); $this->type=image_type_to_extension($this->info['2'],false); $fun="imagecreatefrom{$this->type}"; $this->image=$fun($src); }画像に透かしを入れたり、画像を圧縮したり、画像を切り取ったりすることができる、画像を操作できるクラスライブラリです。 * テキストのウォーターマーク * @param [タイプ] $font Font * @param [タイプ] $content Content * @ param [型] $size 文字サイズ * @param [型] $col 文字色(4値配列) * @param array $location Location * @ param整数 $angle 傾斜角度 * @return [タイプ] * 画像ウォーターマーク * @param [タイプ] $imageMark ウォーターマーク画像アドレス * @param [type] $dst 元画像内の透かし画像の位置 * @param [type] $pct Transparency * @return [type] * 圧縮画像 * @param [タイプ] $thumbSize 圧縮画像サイズ * @return [タイプ] [説明] * 画像のトリミング * @param [type] $cutSize カットサイズ * @param [type] $location カット位置 * @return [type] [説明] * 表示画像 * @return [type] [description] * 画像を保存します * @param [type] $newname 新しい画像名 * @戻り値 [タイプ] [説明]