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 }
function __($item=null) { $__ = new __; if(func_num_args() > 0) $__->_wrapped = $item; return $__; }
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 Slince\Spider\Spider; $spider = new Spider(); $spider->run('http://www.baidu.com');
use QL\QueryList; //採集某頁面全部的圖片 $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 Overtrue\Pinyin\Pinyin; $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"]
$ 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
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%)
$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(); }
composer require php-ai/php-ml require_once 'vendor/autoload.php'; use Phpml\Classification\KNearestNeighbors; $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'
$ffmpeg = FFMpeg\FFMpeg::create(); $video = $ffmpeg->open('video.mpg'); $video ->filters() ->resize(new FFMpeg\Coordinate\Dimension(320, 240)) ->synchronize(); $video ->frame(FFMpeg\Coordinate\TimeCode::fromSeconds(10)) ->save('frame.jpg'); $video ->save(new FFMpeg\Format\Video\X264(), 'export-x264.mp4') ->save(new FFMpeg\Format\Video\WMV(), 'export-wmv.wmv') ->save(new FFMpeg\Format\Video\WebM(), '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/10
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
git clone https://github.com/exinnet/mysqldiff.git cd mysqldiff vi config.php # config mysql connection info php mysqldiff.php
file_get_contents('https://hchk.io/e9ad1415-566c-40c9-9c97-a298d727ab68');
html
composer require overtrue/phplint -vvv use Overtrue\PHPLint\Linter; $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', // ], // ]
// composer require(__DIR__ . "/vendor/autoload.php"); use Md\MDAvatars; $Avatar = new MDAvatars('X', 512); $Avatar->Output2Browser(); $Avatar->Save('./avatars/Avatar256.png', 256);
$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); // 直接返回數據,主進程將在回調中收到 });
$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);
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]
curl -LO https://deployer.org/deployer.phar mv deployer.phar /usr/local/bin/dep chmod +x /usr/local/bin/dep composer require deployer/deployer
公衆號:蘇生不惑java