検索
ホームページバックエンド開発PHPチュートリアルさまざまなプロジェクトで一般的に使用される PHP ツールの包括的なリストを共有する

よく使用される PHP ツールの完全なコレクションを自分のプロジェクトで共有します

PHP コード さまざまなプロジェクトで一般的に使用される PHP ツールの包括的なリストを共有する
  1. /**
  2. * アシスタントクラス
  3. * @author www.shouce.ren
  4. *
  5. */
  6. クラスヘルパー
  7. {
  8. /**
  9. * 現在のサーバー システムを決定します
  10. * @return string
  11. */
  12. public static function getOS(){
  13. if(PATH_SEPARATOR == ':'){
  14. return 'Linux';  
  15. }else{
  16. return 'Windows';  
  17. }
  18. }
  19. /**
  20. * 現在の微妙な番号
  21. * @return 番号
  22. */
  23. public static 関数 microtime_float() {
  24. list ( $usec, $sec ) = explode ( " ", マイクロタイム () );  
  25. return (( float ) $usec ( float ) $sec);  
  26. }  
  27. /**
  28. * UTF-8 形式で文字列を切り取ります (漢字 1 文字または文字が 1 バイトを占めます)
  29. *
  30. * @author zhao jinhan
  31. * @バージョン v1.0.0
  32. *
  33. */
  34. public static function truncate_utf8_string($string, $ length, $etc = '...') {
  35. $result = '';  
  36. $string = html_entity_decode ( trim ( strip_tags ( $string ) ), ENT_QUOTES, 'UTF-8');  
  37. $strlen = strlen ( $string );  
  38. for($i = 0; (($i $strlen) && ($length > 0)); $i ) {
  39. if ($number = strpos ( str_pad ( decbin ( ord ( substr ( $string, $i, 1 ) ) ), 8, '0', STR_PAD_LEFT ), '0' )) {
  40. if ($length
  41. break;  
  42. }
  43. $result .= substr ( $string, $i, $number );  
  44. $length -= 1.0;  
  45. $i = $number - 1;  
  46. } else {
  47. $result .= substr ( $string, $i , 1 );  
  48. $length -= 0.5;  
  49. }
  50. }  
  51. $result = htmlspecialchars ( $result, ENT_QUOTES, 'UTF-8');  
  52. if ($i $strlen) {
  53. $result .= $etc;  
  54. }
  55. return $result;  
  56. }
  57. /**
  58. * フォルダーのトラバース
  59. * @param string $dir
  60. * @param boolean $すべて true は再帰的走査を意味します
  61. * @return array
  62. */
  63. public static function scanfDir($dir='',$all = false, &$ret = array()){
  64. if ( false !== ($handle = opendir ( $dir ))) {
  65. while ( false !== ($file = readdir ( $handle )) ) {
  66. if (!in_array($file,array('.','..','.git','.gitignore) ','.svn','.htaccess','.buildpath','.project'))) {
  67. $cur_path = $dir 。 '/' 。 $file;  
  68. if (is_dir ( $cur_path )) {
  69. $ret['dirs'][] =$cur_path;  
  70. $all && self::scanfDir( $cur_path, $all, $ret);  
  71. } else {
  72. $ret [ 「ファイル」] [] = $cur_path;  
  73. }
  74. }  
  75. }
  76. closedir ( $handle );  
  77. }
  78. return $ret;  
  79. }
  80. /** 
  81. * 邮件送信
  82. * @param string $toemail
  83. * @param string $ subject
  84. * @param string $message
  85. * @return boolean
  86.      */
  87. public static function sendMail($toemail = ' ', $subject = '', $message = '') {
  88. $mailer = Yii::createComponent ('application.extensions.mailer.EMailer');
  89. //メール設定
  90. ;Host = Yii::app()->params['emailHost'];メールサーバー
  91. $mailer ->Port = Yii::app()->params['emailPort']//メールポート ;
  92. $ mailer->Timeout = Yii::app()->params['emailTimeout'];//メール送信タイムアウト
  93. 🎜>$mailer->ContentType =
  94. 'text/html';//HTML 形式を設定
  95. $mailer->SMTPAuth = true;
  96. $mailer->Password = Yii::app()->params['emailPassword'];
  97. $mailer->IsSMTP ();
  98. $mailer->FromName = Yii::app()->params[
  99. 'emailFormName']; // 送信者名
  100. $mailer->AddReplyTo ($mailer->Username);
  101. $mailer ->CharSet = 'UTF-8';
  102. 🎜>new MailLog (); $modelMail->subject = $subject
  103. $modelMail->send_status = '待機中';  
  104. $modelMail->save ();  
  105. // 送信邮件
  106. $mailer->AddAddress ( $toemail );  
  107. $mailer->件名 = $subject;  
  108. $mailer->本文 = $message;  
  109. if ($mailer->Send () === true) {
  110. $ modelMail->times = $modelMail->times 1;  
  111. $modelMail->send_status = '成功';  
  112. $modelMail->save ();  
  113. true を返します。  
  114. } else {
  115. $error = $mailer->ErrorInfo;  
  116. $modelMail->times = $modelMail->times 1;  
  117. $modelMail->send_status = '失敗';  
  118. $modelMail->error = $error;  
  119. $modelMail->save ();  
  120. return false;  
  121. }
  122. }
  123. /**
  124. * 文字列が utf-8 か gb2312 かを判断します
  125. * @param 不明 $str
  126. * @param string $default
  127. * @return string
  128. */
  129. public static function utf8_gb2312($str, $デフォルト = 'gb2312')
  130. >"/[x01-x7F] /",
  131. "",
  132. $str); 空($str))
  133. return
  134. $preg; = array( "gb2312" => "/^([xA1-xF7][xA0-xFE]) $/" , //gb2312
  135. {9FA5}] $/u",
  136. // 漢字かどうかの定期判定(条件) utf8 エンコードの場合)、この範囲には実際には繁体字中国語の文字が含まれます
  137. ); 'gb2312') { 🎜>$ オプション =
  138. 'utf-8' ; ; 🎜>
  139. $ str = @iconv($default, $option, $str);
  140. // $option を変換できません。元のオプションが $default ではないことを示します。 if (
  141. empty
  142. empty($str)) {
  143. デフォルト;
  144. }  
  145. /**
  146. * UTF-8 および gb2312 自動変換
  147. * @param 不明 $string
  148. * @param string $outEncoding
  149. * @return 不明|文字列
  150. */
  151. public static function safeEncoding($string,$ outEncoding = 'UTF-8')
  152. {
  153. $encoding = 「UTF-8」;  
  154. for($i = 0; $i strlen ( $string ); $i ) {
  155. if (ord ( $string {$i} )
  156. 続き;  
  157. if ((ord ( $string {$i} ) & 224) == 224) {
  158. // 第一字节判断通过
  159. $char = $string { $i};  
  160. if ((ord ( $char ) & 128) == 128) {
  161. // 第二个字节判断通过
  162. $char = $string { $i};  
  163. if ((ord ( $char ) & 128) == 128) {
  164. $encoding = "UTF-8";  
  165. 休憩;  
  166. }
  167. }
  168. }
  169. if ((ord ( $string {$i}) & 192) == 192) {
  170. = $string { $i}; 🎜>
  171. { strtoupper ( $outEncoding ))
  172. return $string;
  173. } > public
  174. static
  175. function array_key_values($array =array(),
  176. $key=
  177. '')
  178. 🎜 >foreach((配列)$array $k=>$v){
  179. $ret[
  180. $ k] =$ v [$ key];  
  181. /**
  182. * ファイル/ディレクトリが書き込み可能かどうかを判断します (システムに付属の is_writeable 関数を置き換えます)
  183. * @param string $fileファイル/ディレクトリ
  184. * @return boolean
  185. */
  186. public static function is_writeable($file) {
  187. if (is_dir($file)){
  188. $dir = $file;  
  189. if ($fp = @fopen("$dir/test.txt", 'w')) {
  190. @fclose($fp);  
  191. @unlink("$dir/test.txt");  
  192. $writeable = 1;  
  193. } else {
  194. $writeable = 0;  
  195. }
  196. } else {
  197. if ($fp = @fopen($file, 'a ')) {
  198. @fclose($fp);  
  199. $writeable = 1;  
  200. } else {
  201. $writeable = 0;  
  202. }
  203. }
  204. return $writeable;  
  205. }  
  206. /**
  207. * フォーマット単位
  208. */
  209. static public function byteFormat( $size, $ dec = 2 ) {
  210. $a = array ( "B" , "KB" 、"MB"、"GB"、"TB"、"PB");  
  211. $pos = 0;  
  212. while ( $size >= 1024 ) {
  213. $size /= 1024;  
  214. $pos ;  
  215. }
  216. return round( $size, $dec ) 。 「 」 。 $a[$pos];  
  217. }
  218. /**
  219. * ドロップダウンボックス、ラジオボタン自動選択
  220. *
  221. * @param $ string 入力文字
  222. * @param $param 条件
  223. * @param $type Type
  224. * 選択済み、チェック済み
  225. * @return string
  226. */
  227. static public function selected( $string, $param = 1, $type = 'select' ) {
  228. $true = false;  
  229. if ( is_array( $param ) ) {
  230. $true = in_arレイ( $string, $param );  
  231. }elseif ( $string == $param ) {
  232. $true = true;  
  233. }  
  234. $return='';  
  235. if ( $true )
  236. $return = $type == 「選択」? 'selected="選択済み"' : 'checked="チェック済み"';  
  237. echo $return;  
  238. }
  239. /**
  240. * リモート画像のダウンロード
  241. * @param string $url 画像の絶対 URL
  242. * @param string $filepath ファイルのフルパス (/www/images/test など) この関数は、画像の URL と http ヘッダー情報に基づいて画像のサフィックス名を自動的に決定します
  243. * @ param string $filename 保存するファイル名(拡張子は除く)
  244. * @returnmixed ダウンロードが成功した場合、ファイル名を記述する配列ダウンロードに失敗した場合は画像情報が返されます。
  245. が返されます。*/
  246. static public function downloadImage($url, $ filepath, $filename) {
  247. //サーバーから返されたヘッダー情報
  248. $responseHeaders = array();
  249. //元の画像名
  250. originalfilename = ';
  251. >
  252. $ch =curl_init(
  253. $url); > //curl_exec によって返される値に HTTP ヘッダーを含めるように設定します curl_setopt(
  254. $ch, CURLOPT_HEADER, 1); >//curl_exec によって返される値に Http コンテンツを含めるように設定します
  255. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1)
  256. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  257. //HTTP リダイレクトの最大数を設定します
  258. curl_ setopt($ch, CURLOPT_MAXREDIRS , 3);
  259. //サーバーから返されたデータ (http ヘッダー情報とコンテンツを含む)
  260. $html =curl_exec($ch);
  261. // このクロールに関する関連情報を取得します
  262. $httpinfo =curl_getinfo(
  263. $ch) ;); ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ タイムス串
  264. $ httparr = Explode ( "" rnrn ",
  265. $ html, 2
  266. $ httpinfo [ 'redirect_count']] );
  267. //最後から 2 番目の段落はサーバーの最後の応答の http ヘッダーです
  268. $header = $httpArr[count($ httpArr) - 2];
  269. 🎜>$body = $httpArr[count(
  270. $httpArr) - 1];
  271. $header = "rn" ):s*([^rn] ) rn/i', $header,
  272. $matches);
  273. >$matches[ 1]) && !
  274. 空($matches[1])) {
  275. for ($i = 0; $i count($matches[1]); $i ) { $i, $matches[2])) { $i]] =
  276. $matches[2][
  277. $i]; } '{(?:[ ^/\\] ).(jpg|jpeg|gif|png|bmp)$}i', $url, $matches)) {
  278. $originalfilename = $matches[0];
  279. > >i', $responseHeaders['Content-Type'], $extmatches)) {
  280. >$ ext =$ extmatches [1];ディレクトリが存在しない場合は、まずディレクトリを作成する必要があります。 🎜> 🎜>
  281. ファイルパス .=
  282. '/'.
  283. $filename.
  284. "。 $ext";
  285. $local_file =
  286. fopen($filepath, 'w'); ) {
  287. >
  288. fclose(
  289. $local_file); > 0], '高さ' => $sizeinfo[1],
  290. '元のファイル名' =>;
  291. $元のファイル名, 'ファイル名' => ; パス情報($filepath, PATHINFO_BASENAME));
  292. false を返す
  293. }  
  294. /**
  295. * IP が特定のセグメントにあるかどうかを検索
  296. * @param string $ip クエリされる IP
  297. * @param $arrIP 禁止 IP
  298. * @return boolean
  299. */
  300. public static function ipAccess($ip=' 0.0.0.0',$arrIP = array()){
  301. $アクセス = true;  
  302. $ip && $arr_cur_ip = explode('.',$ip);  
  303. foreach((array)$arrIP as $key=> $value){
  304. if($value == '*.*. *.*'){
  305. $access = false; // 禁止すべて
  306. break;  
  307. }
  308. $tmp_arr = explode('.', $value);  
  309. if(($arr_cur_ip[0] == $tmp_arr[0]) && ($arr_cur_ip [1] == $tmp_arr[1])) {
  310. //前二段同様
  311. if(($arr_cur_ip[2] == $tmp_arr[2]) || ($tmp_arr[2] == '*') ){
  312. // 第三段は* または者と同じ
  313. if(( $arr_cur_ip[3] == $tmp_arr[3]) || ($tmp_arr[3] == '*')){
  314. //第四段は* または者と同じ
  315. $access = falせ; //在禁止ip列,则禁止访问
  316. break;  
  317. }
  318. }  
  319. }
  320. }
  321. return $access;  
  322. }
  323. /**
  324. * @param string $string 元のテキストまたは暗号文
  325. * @param string $operation 操作 (ENCODE | DECODE)、デフォルトis DECODE
  326. * @param string $key Key
  327. * @param int $expiry 暗号文の有効期間、暗号化中に有効、単位は秒、 0 永続的に有効です
  328. * @return string 処理された元のテキスト、またはbase64_encodeで処理された暗号文
  329. *
  330. * @example
  331. * ') 🎜> *
  332. * $a = 認証コード('abc' , 'ENCODE', 'key', 3600);
  333. * $ b = authcode('abc', 'DECODE', 'key'); // 1 時間以内に $ b(abc)、それ以外の場合、$b は空です
  334. */
  335. public
声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。
PHPアプリケーションをより速くする方法PHPアプリケーションをより速くする方法May 12, 2025 am 12:12 AM

tomakephpapplicationsfaster、followthesesteps:1)useopcodecachinglikeopcacheTostoredscriptbytecode.2)最小化abasequeriesecachingingindexing.3)leveragephp7機能forbettercodeefficiency.4)

PHP依存性インジェクション:コードのテスト可能性を改善しますPHP依存性インジェクション:コードのテスト可能性を改善しますMay 12, 2025 am 12:03 AM

依存性注入(DI)は、明示的に推移的な依存関係によりPHPコードのテスト可能性を大幅に改善します。 1)DI分離クラスと特定の実装により、テストとメンテナンスが柔軟になります。 2)3つのタイプのうち、コンストラクターは、状態を一貫性に保つために明示的な式依存性を注入します。 3)DIコンテナを使用して複雑な依存関係を管理し、コードの品質と開発効率を向上させます。

PHPパフォーマンスの最適化:データベースクエリの最適化PHPパフォーマンスの最適化:データベースクエリの最適化May 12, 2025 am 12:02 AM

DatabaseQueryoptimizationInpholvesseveralstrategESTOEnhancePerformance.1)selectonlynlynlyndorycolumnStoredatedataTransfer.2)useindexingtospeedupdataretrieval.3)revenmecrycachingtostoreres sultsoffrequent queries.4)

簡単なガイド:PHPスクリプトで電子メールを送信します簡単なガイド:PHPスクリプトで電子メールを送信しますMay 12, 2025 am 12:02 AM

phpisusededemingemailsduetoitsbuilt-inmail()functionandsupportiveLibrarieslikephpmailerandswiftmailer.1)usethemail()functionforbasicemails、butithaslimitations.2)emploadforadvancedfeatureSlikelikelivableabableabuses.3)雇用

PHPパフォーマンス:ボトルネックの識別と修正PHPパフォーマンス:ボトルネックの識別と修正May 11, 2025 am 12:13 AM

PHPパフォーマンスボトルネックは、次の手順で解決できます。1)パフォーマンス分析にXdebugまたはBlackfireを使用して問題を見つける。 2)データベースクエリを最適化し、APCUなどのキャッシュを使用します。 3)array_filterなどの効率的な関数を使用して、配列操作を最適化します。 4)bytecodeキャッシュ用のopcacheを構成します。 5)HTTP要求の削減や写真の最適化など、フロントエンドを最適化します。 6)パフォーマンスを継続的に監視および最適化します。これらの方法により、PHPアプリケーションのパフォーマンスを大幅に改善できます。

PHPの依存関係注射:簡単な要約PHPの依存関係注射:簡単な要約May 11, 2025 am 12:09 AM

依存関係(di)inphpisadesignpatternativats anducesclassodulencies、拡張測定性、テスト可能性、および維持可能性。

PHPパフォーマンスの向上:キャッシュ戦略と技術PHPパフォーマンスの向上:キャッシュ戦略と技術May 11, 2025 am 12:08 AM

cachingemprovesppperformancebystring of computationsorquickretrieval、還元装置の削減は、reducingerloadendenhancersponseTimes.efcectivestrategiesInclude:1)opcodecaching、compiledphpscriptsinmemorytoskipcompilation;

See all articles

ホットAIツール

Undresser.AI Undress

Undresser.AI Undress

リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover

AI Clothes Remover

写真から衣服を削除するオンライン AI ツール。

Undress AI Tool

Undress AI Tool

脱衣画像を無料で

Clothoff.io

Clothoff.io

AI衣類リムーバー

Video Face Swap

Video Face Swap

完全無料の AI 顔交換ツールを使用して、あらゆるビデオの顔を簡単に交換できます。

ホットツール

ゼンドスタジオ 13.0.1

ゼンドスタジオ 13.0.1

強力な PHP 統合開発環境

Dreamweaver Mac版

Dreamweaver Mac版

ビジュアル Web 開発ツール

MantisBT

MantisBT

Mantis は、製品の欠陥追跡を支援するために設計された、導入が簡単な Web ベースの欠陥追跡ツールです。 PHP、MySQL、Web サーバーが必要です。デモおよびホスティング サービスをチェックしてください。

SublimeText3 中国語版

SublimeText3 中国語版

中国語版、とても使いやすい

SublimeText3 英語版

SublimeText3 英語版

推奨: Win バージョン、コードプロンプトをサポート!