推荐值得的8个实用PHP库
1.pinyin(中文转拼音工具)
项目地址:https://github.com/overtrue/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=豆瓣高分&sort=time&page_limit=20&page_start=1";
$curl->get($url);
$curl->setOpt(CURLOPT_SSL_VERIFYPEER, false);
$curl->close();
var_dump($curl->getResponse());exit;
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 namespace
use 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)等文档格式
<?php
require_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 命令行应用库。提供控制台参数解析、命令运行、颜色风格输出、 用户信息交互等功
这篇好文章是转载于:学新通技术网
- 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
- 本站站名: 学新通技术网
- 本文地址: /news/detail/tancbg
-
从《银行业金融机构数据治理指引》监管要求看商业银行数据能力建设
51CTO 09-21 -
2023 年度 A 类学科竞赛项目清单
那个人有梦想 09-16 -
爱思唯尔的ESWA——模板、投稿、返修、接收的
老板来碗小面加蛋~ 09-16 -
国航天科技集团公司的各个研究院
知识在于积累 09-17 -
全球WIFI功率信号最强的国家清单,无线WIFI调优
Cisco_VIP 09-17 -
ChatGPT注册流程攻略,含验证码接收
PHP中文网 05-29 -
AI绘画Midjourney的咒语关键词汇
毕设小程序软件程序猿 09-17 -
创作者身份认证申请规则和审核标准
CSDN官方博客 09-16 -
的10 个顶尖的国内外设计网站
四喜圆子- 09-16 -
OBS做绿幕直播滤镜实现去掉绿色背景
视频砖家 09-16