PHP中文网为同学们整理了github上Star比较高的8个实用的PHP库,提升开发效率。

1.pinyin(中文转拼音工具)

基于 CC-CEDICT 词典的中文转拼音工具,更准确的支持多音字的汉字转拼音解决方案,示例代码:


(相关资料图)

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

2.php-curl-class(PHP cURL 库)

项目地址:https://github.com/php-curl-class/php-curl-class

该开源项目封装了 PHP 的 cURL 库,使得发送 HTTP 请求变得简单。适用于需要 PHP 爬虫或者其它模拟 HTTP 访问的情况,示例代码:

<?php// 获取豆瓣电影示例require "../vendor/autoload.php";use Curl\Curl;$curl = new Curl();$url = "https://movie.douban.com/j/search_subjects?type=movie&tag=%E8%B1%86%E7%93%A3%E9%AB%98%E5%88%86&sort=time&page_limit=20&page_start=1";$curl->get($url);$curl->setOpt(CURLOPT_SSL_VERIFYPEER, false);$curl->close();var_dump($curl->getResponse());exit;

php入门到就业线上直播课:进入学习Apipost = Postman + Swagger + Mock + Jmeter 超好用的API调试工具:点击使用

3.parsedown(Markdown 解析库)

项目地址:https://github.com/erusev/parsedown

一个小而美的 PHP 的 Markdown 解析库。该库提供了标准 Markdown 文本转化成 HTML 字符串功能,并拥有良好的文档。它的主文件只有一个,除了 PHP 版本限制必须高于 5.3 外几乎无依赖,可通过 composer 引入,也可以直接使用 Parsedown.php 文件。该项目中使用大量正则表达式,可作为学习正则表达式的示例,并且有完整的单元测试。示例代码:

$Parsedown = new Parsedown();echo $Parsedown->text("Hello _Parsedown_!"); # prints: <p>Hello <em>Parsedown</em>!</p>

4.dompdf(HTML 转 PDF)

项目地址:https://github.com/dompdf/dompdf

一个 HTML 转 PDF 的 PHP 库。示例代码:

// reference the Dompdf namespaceuse Dompdf\Dompdf;// instantiate and use the dompdf class$dompdf = new Dompdf();$dompdf->loadHtml("hello world");// (Optional) Setup the paper size and orientation$dompdf->setPaper("A4", "landscape");// Render the HTML as PDF$dompdf->render();// Output the generated PDF to Browser$dompdf->stream();

5.PHPWord(电商平台)

项目地址:https://github.com/PHPOffice/PHPWord

提供了读/写多种文档文件格式的 PHP 库。支持 Microsoft Office、富文本(RTF)等文档格式

<?phprequire_once "bootstrap.php";// 新建文档$phpWord = new \PhpOffice\PhpWord\PhpWord();// Adding an empty Section to the document...$section = $phpWord->addSection();// Adding Text element to the Section having font styled by default...$section->addText(    ""Learn from yesterday, live for today, hope for tomorrow. "        . "The important thing is not to stop questioning." "        . "(Albert Einstein)");

6.easy-sms(短信发送 )

项目地址:https://github.com/overtrue/easy-sms

短信发送 PHP 组件。特点:

支持目前市面多家服务商

一套写法兼容所有平台

简单配置即可灵活增减服务商

内置多种服务商轮询策略、支持自定义轮询策略

use Overtrue\EasySms\EasySms;$config = [    // HTTP 请求的超时时间(秒)    "timeout" => 5.0,    // 默认发送配置    "default" => [        // 网关调用策略,默认:顺序调用        "strategy" => \Overtrue\EasySms\Strategies\OrderStrategy::class,        // 默认可用的发送网关        "gateways" => [            "yunpian", "aliyun",        ],    ],    // 可用的网关配置    "gateways" => [        "errorlog" => [            "file" => "/tmp/easy-sms.log",        ],        "yunpian" => [            "api_key" => "824f0ff2f71cab52936axxxxxxxxxx",        ],        "aliyun" => [            "access_key_id" => "",            "access_key_secret" => "",            "sign_name" => "",        ],        //...    ],];$easySms = new EasySms($config);$easySms->send(13188888888, [    "content"  => "您的验证码为: 6379",    "template" => "SMS_001",    "data" => [        "code" => 6379    ],

7.YOURLS(短网址生成)

项目地址:https://github.com/YOURLS/YOURLS

完全免费的短网址服务。采用 PHP 编写的短网址服务,它完全开源可自行搭建服务,支持数据统计、地理位置、可视化等功能。

8.php-console(PHP 命令行应用库)

项目地址:https://github.com/inhere/php-console

使用简单,功能全面的 PHP 命令行应用库。提供控制台参数解析、命令运行、颜色风格输出、 用户信息交互等功能

开班通知:

php中文网第《22期PHP线上直播班》正式开始报名了!

授课形式:

1.零基础开始,前端到后端,系统的学习!

2.直播同步录播,内部群,老师作业批改,辅导解答,督促学习

限额活动:

1.前50名报名同学,即赠送三部实战课程,先到先得,送完为止!

2.报名即赠送一套完整PHP课程(超值),课前学习!(限前10名)

报名咨询↓↓↓

QQ报名:27220243(钟老师)

微信报名:phpcn01(月月老师)

(长按识别,在线咨询)

推荐内容