PHP 函數的 JavaScript 實現
module.exports = function array_sum (array) { // eslint-disable-line camelcase // discuss at: http://locutus.io/php/array_sum/ // original by: Kevin van Zonneveld (http://kvz.io) // bugfixed by: Nate // bugfixed by: Gilbert // improved by: David Pilia (http://www.beteck.it/) // improved by: Brett Zamir (http://brett-zamir.me) // example 1: array_sum([4, 9, 182.6]) // returns 1: 195.6 // example 2: var $total = [] // example 2: var $index = 0.1 // example 2: for (var $y = 0; $y < 12; $y++){ $total[$y] = $y + $index } // example 2: array_sum($total) // returns 2: 67.2 var key var sum = 0 // input sanitation if (typeof array !== "object") { return null } for (key in array) { if (!isNaN(parseFloat(array[key]))) { sum += parseFloat(array[key]) } } return sum }Underscore.js 的 PHP 版
function __($item=null) { $__ = new __; if(func_num_args() > 0) $__->_wrapped = $item; return $__; }自動生成 gitignore 文件
https://www.gitignore.io/api/laravel # Created by https://www.gitignore.io/api/laravel ### Laravel ### vendor/ node_modules/ npm-debug.log # Laravel 4 specific bootstrap/compiled.php app/storage/ # Laravel 5 & Lumen specific public/storage public/hot storage/*.key .env.*.php .env.php .env Homestead.yaml Homestead.json # Rocketeer PHP task runner and deployment package. https://github.com/rocketeers/rocketeer .rocketeer/ # End of https://www.gitignore.io/api/laravel爬蟲組件
composer global require slince/spider *@dev use SlinceSpiderSpider; $spider = new Spider(); $spider->run("http://www.baidu.com");簡單、 靈活、強大的 PHP 采集工具
use QLQueryList; //采集某頁面所有的圖片 $data = QueryList::Query("http://cms.querylist.cc/bizhi/453.html",array( //采集規則庫 //"規則名" => array("jQuery選擇器","要采集的屬性"), "image" => array("img","src") ))->data; //打印結果 print_r($data); //采集某頁面所有的超鏈接 //可以先手動獲取要采集的頁面源碼 $html = file_get_contents("http://cms.querylist.cc/google/list_1.html"); //然后可以把頁面源碼或者HTML片段傳給QueryList $data = QueryList::Query($html,array( "link" => array("a","href") ))->data; //打印結果 print_r($data); 在線測試采集并查看采集結果 http://querylist.cc/page-Querytest.html在線測試代碼
$array=[ ["name"=>"張三","age"=>"23"], ["name"=>"李四","age"=>"64"], ["name"=>"王五","age"=>"55"], ["name"=>"趙六","age"=>"66"], ["name"=>"孫七","age"=>"17"], ]; $sort = array( "direction" => "SORT_ASC", //排序順序標志 SORT_DESC 降序;SORT_ASC 升序 "field" => "age", //排序字段 ); $arrSort = array(); foreach($array as $uniqid => $row){ foreach($row AS $key=>$value){ $arrSort[$key][$uniqid] = $value; } } array_multisort($arrSort[$sort["field"]], constant($sort["direction"]), $array); print_r($array);中文轉拼音工具
//https://hellogithub.com/category/PHP%20%E9%A1%B9%E7%9B%AE/ use OvertruePinyinPinyin; $pinyin = new Pinyin(); $pinyin->convert("帶著希望去旅行,比到達終點更美好"); // ["dai", "zhe", "xi", "wang", "qu", "lv", "xing", "bi", "dao", "da", "zhong", "dian", "geng", "mei", "hao"] $pinyin->convert("帶著希望去旅行,比到達終點更美好", PINYIN_UNICODE); // ["dài","zhe","xī","wàng","qù","lǚ","xíng","bǐ","dào","dá","zhōng","diǎn","gèng","měi","hǎo"] $pinyin->convert("帶著希望去旅行,比到達終點更美好", PINYIN_ASCII); //["dai4","zhe","xi1","wang4","qu4","lv3","xing2","bi3","dao4","da2","zhong1","dian3","geng4","mei3","hao3"]美化 curl
$ git clone https://github.com/talhasch/php-httpstat $ cd php-httpstat $ cp httpstat.php /usr/local/bin/httpstat $ chmod +x /usr/local/bin/httpstat $ httpstat http://www.google.com在線正則表達式測試 在線測試 redis 在線練習 git 檢測 PHP 應用的代碼復雜度
composer global require "phploc/phploc=*" $ phploc src phploc 4.0.0 by Sebastian Bergmann. Directories 3 Files 10 Size Lines of Code (LOC) 1882 Comment Lines of Code (CLOC) 255 (13.55%) Non-Comment Lines of Code (NCLOC) 1627 (86.45%) Logical Lines of Code (LLOC) 377 (20.03%) Classes 351 (93.10%) Average Class Length 35 Minimum Class Length 0 Maximum Class Length 172 Average Method Length 2 Minimum Method Length 1 Maximum Method Length 117 Functions 0 (0.00%) Average Function Length 0 Not in classes or functions 26 (6.90%)php http 請求工具
$response = Zttp::withHeaders(["Fancy" => "Pants"])->post($url, [ "foo" => "bar", "baz" => "qux", ]); $response->json(); // => [ // "whatever" => "was returned", // ];任務管理
composer global require consolidation/robo class RoboFile { /** * Each public method is a command in runner * parameters are arguments in console * * use "./robo test" to run tests on a project */ function test($pathToSelenium = "~/selenium.jar") { // starts PHP server in background $this->taskPhpServer(8000) ->background() ->dir("web") ->run(); // launches Selenium server $this->taskExec("java -jar ".$pathToSelenium) ->background() ->run(); // runs PHPUnit tests $this->taskPHPUnit() ->run(); }phpstorm 技巧 php ai
composer require php-ai/php-ml require_once "vendor/autoload.php"; use PhpmlClassificationKNearestNeighbors; $samples = [[1, 3], [1, 4], [2, 4], [3, 1], [4, 1], [4, 2]]; $labels = ["a", "a", "a", "b", "b", "b"]; $classifier = new KNearestNeighbors(); $classifier->train($samples, $labels); echo $classifier->predict([3, 2]); // return "b"PHP driver for FFMpeg
$ffmpeg = FFMpegFFMpeg::create(); $video = $ffmpeg->open("video.mpg"); $video ->filters() ->resize(new FFMpegCoordinateDimension(320, 240)) ->synchronize(); $video ->frame(FFMpegCoordinateTimeCode::fromSeconds(10)) ->save("frame.jpg"); $video ->save(new FFMpegFormatVideoX264(), "export-x264.mp4") ->save(new FFMpegFormatVideoWMV(), "export-wmv.wmv") ->save(new FFMpegFormatVideoWebM(), "export-webm.webm");編碼格式化工具
//http://cs.sensiolabs.org/ composer global require fabpot/php-cs-fixer //wget http://get.sensiolabs.org/php-cs-fixer.phar -O php-cs-fixer curl http://get.sensiolabs.org/php-cs-fixer.phar -o php-cs-fixer sudo chmod a+x php-cs-fixer sudo mv php-cs-fixer /usr/local/bin/php-cs-fixer # 格式化目錄 如果是當前目錄的話可以省略目錄 php-cs-fixer fix /path/to/dir # 格式化文件 php-cs-fixer.phar fix /path/to/file //cat foo.php | php-cs-fixer fix --diff - #https://housanpai.com/articles/10php medoo
composer require catfan/Medoo // 如果你通過 composer 安裝, 只需在項目的開始部分加上此代碼即可自動加載。 require "vendor/autoload.php"; // 或者你是下載 medoo.php 并放置到項目目錄中,require 即可。 require "medoo.php"; $database = new medoo([ // 必須的 "database_type" => "mysql", "database_name" => "name", "server" => "localhost", "username" => "your_username", "password" => "your_password", "charset" => "utf8", // [可選] "port" => 3306, // [可選] 表名前綴 "prefix" => "PREFIX_", // [可選] 連接的驅動選項,請閱讀 http://www.php.net/manual/en/pdo.setattribute.php "option" => [ PDO::ATTR_CASE => PDO::CASE_NATURAL ] ]); $database->insert("account", [ "user_name" => "foo", "email" => "foo@bar.com" ]);在線文檔分享工具
composer create-project showdoc/showdoc
php的ngrok客戶端 比對兩個數據庫的表結構,并自動修正git clone https://github.com/exinnet/mysqldiff.git cd mysqldiff vi config.php # config mysql connection info php mysqldiff.phpcron
file_get_contents("https://hchk.io/e9ad1415-566c-40c9-9c97-a298d727ab68");
語法檢測composer require overtrue/phplint -vvv use OvertruePHPLintLinter; $path = __DIR__ ."/app"; $exclude = ["vendor"]; $extensions = ["php"]; $linter = new Linter($path, $exclude, $extensions); // get errors $errors = $linter->lint(); // // [ // "/path/to/foo.php" => [ // "error" => "unexpected "$key" (T_VARIABLE)", // "line" => 168, // "file" => "/path/to/foo.php", // ], // "/path/to/bar.php" => [ // "error" => "unexpected "class" (T_CLASS), expecting "," or ";"", // "line" => 28, // "file" => "/path/to/bar.php", // ], // ]生成Material Design風格頭像
// composer require(__DIR__ . "/vendor/autoload.php"); use MdMDAvatars; $Avatar = new MDAvatars("X", 512); $Avatar->Output2Browser(); $Avatar->Save("./avatars/Avatar256.png", 256);使用screw plus來保護php代碼安全 一個最精簡的php多進程控制庫
$sf = new SimpleFork(2, "my-process"); // 2代表子進程數, "my-process"是進程的名字 $sf->master(function ($sf) { // 主進程的方法請包裹在master里 while ($sf->loop(100)) { // 100為等待的毫秒數 $sf->submit("http://www.google.cn/", function ($data) { // 使用submit方法將其提交到一個空閑的進程,如果沒有空閑的,系統會自動等待 echo $data; }); } })->slave(function ($url, $sf) { $sf->log("fetch %s", $url); // 使用內置的log方法,子進程的log也會被打印到主進程里 return http_request($url); // 直接返回數據,主進程將在回調中收到 });A PHP MySQL PDO class similar to the the Python MySQLdb
$DB->query("SELECT * FROM fruit WHERE name=".$_GET["name"]); $DB->query("SELECT * FROM fruit WHERE name=? and color=?",array("apple","red")); $DB->query("SELECT * FROM fruit WHERE name=:name and color=:color",array("name"=>"apple","color"=>"red")); $DB->query("SELECT * FROM fruit WHERE name IN (?)",array("apple","banana"));圖片處理
$ch = curl_init(); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($ch, CURLOPT_URL, "https://avatars0.githubusercontent.com/u/5785188?v=3&s=460"); $response = curl_exec($ch); curl_close($ch); $UploadAvatar = new ImageResize("String", $response); $Result = $UploadAvatar->Resize(256, "upload/avatar/large.png", 80);Linux 圖形化性能監視器 編寫PHP代碼片段終極機器人 PHP 代碼轉 Python
def substr (self, s, start, length = None): """Returns the portion of string specified by the start and length parameters. """ if len(s) >= start: if start > 0: return False else: return s[start:] if not length: return s[start:] elif length > 0: return s[start:start + length] else: return s[start:length]php部署工具
curl -LO https://deployer.org/deployer.phar mv deployer.phar /usr/local/bin/dep chmod +x /usr/local/bin/dep composer require deployer/deployer
公眾號:蘇生不惑
文章版權歸作者所有,未經允許請勿轉載,若此文章存在違規行為,您可以聯系管理員刪除。
轉載請注明本文地址:http://specialneedsforspecialkids.com/yun/23273.html
摘要:具體來說,包管理器就是可以通過命令行,幫助你把外部庫和插件放到你的項目里面并在之后進行版本升級,這樣就不用手工復制和更新庫。現在有的包管理器主要是和。 一、基礎 1、學習HTML基礎 HTML給你的網頁賦予了結構。它就像是人的骨架那樣讓你保持站立。首先你需要去學習語法以及它必須提供的一切。你的學習應該聚焦在下面這些東西上: 學習HTML基礎,了解如何編寫語義HTML 理解如何把網頁分...
摘要:最近這六年來,一直使用開源系統來做項目,如等,雖然也有接觸過主流的框架,不過并不多。互聯網快速迭代我是互聯網比較早的用戶了,我學的時候還沒有所謂的框架,所以那時候開發出一個好用的框架無疑是提高生產力最佳的方案。 最近這六年來,一直使用PHP開源系統來做項目,如drupal, joomla, wordpress, magento等,雖然也有接觸過主流的框架,不過并不多。也許我會有一些偏見...
摘要:今日勵志語錄有志者自有千計萬計,無志者只感千難萬難。三動畫技術越來越不陌生,使用門檻也漸漸降低,而且動畫還可以使用控制。掃一掃查看效果打開微掃一掃關注早讀君,每天早晨為你推送前端知識,度過擠地鐵坐公交的時光 今日勵志語錄有志者自有千計萬計,無志者只感千難萬難。 文章原出處:騰訊ISUX 開始閱讀之前你可以先掃一掃體驗demoshowImg(https://segmentfault.co...
閱讀 2423·2021-10-09 09:59
閱讀 2177·2021-09-23 11:30
閱讀 2591·2019-08-30 15:56
閱讀 1145·2019-08-30 14:00
閱讀 2938·2019-08-29 12:37
閱讀 1252·2019-08-28 18:16
閱讀 1655·2019-08-27 10:56
閱讀 1021·2019-08-26 17:23