彩票走势图

分享一些PHP开发者实用工具(上)

原创|行业资讯|编辑:蒋永|2017-07-18 14:54:32.000|阅读 744 次

概述:今天小编给大家整理了一些php开发中可能需要用到的工具或组建,需要的朋友可以参考和收藏哦~

# 慧都年终大促·界面/图表报表/文档/IDE等千款热门软控件火热促销中 >>

今天小编给大家整理了一些php开发中可能需要用到的工具或组建,需要的朋友可以参考和收藏哦~

PHP 函数的 JavaScript 实现

module.exports = function array_sum (array) { // eslint-disable-line camelcase
  //  discuss at: //locutus.io/php/array_sum/
  // original by: Kevin van Zonneveld (//kvz.io)
  // bugfixed by: Nate
  // bugfixed by: Gilbert
  // improved by: David Pilia (//www.beteck.it/)
  // improved by: Brett Zamir (//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 文件

//www.gitignore.io/api/laravel
# Created by //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. //github.com/rocketeers/rocketeer
.rocketeer/

# End of //www.gitignore.io/api/laravel

爬虫组件

composer global require slince/spider *@dev
use Slince\Spider\Spider;

$spider = new Spider();
$spider->run('//www.baidu.com');

简单、 灵活、强大的 PHP 采集工具

use QL\QueryList;
//采集某页面所有的图片
$data = QueryList::Query('//cms.querylist.cc/bizhi/453.html',array(
    //采集规则库
    //'规则名' => array('jQuery选择器','要采集的属性'),
    'image' => array('img','src')
    ))->data;
//打印结果
print_r($data);

//采集某页面所有的超链接
//可以先手动获取要采集的页面源码
$html = file_get_contents('//cms.querylist.cc/google/list_1.html');
//然后可以把页面源码或者HTML片段传给QueryList
$data = QueryList::Query($html,array(
    'link' => array('a','href')
    ))->data;
//打印结果
print_r($data);
在线测试采集并查看采集结果 //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);

中文转拼音工具

////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"]

因为篇幅的原因,本次的分享就到这里啦,下次讲给大家带来更多php开发实用工具~


轻量级且便捷的PHP IDE PhpStorm加入在线订购快捷通道!续费更有优惠,戳这里看详情>>>


标签:PHPPHPIDE

本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@cahobeh.cn


为你推荐

  • 推荐视频
  • 推荐活动
  • 推荐产品
  • 推荐文章
  • 慧都慧问
扫码咨询


添加微信 立即咨询

电话咨询

客服热线
023-68661681

TOP