首頁  >  文章  >  【整理推薦】值得收藏的8個實用PHP庫

【整理推薦】值得收藏的8個實用PHP庫

青灯夜游
青灯夜游原創
2022-12-19 15:00:372275瀏覽

PHP中文網為同學整理了github上Star比較高的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 &#39;../vendor/autoload.php&#39;;
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;

【整理推薦】值得收藏的8個實用PHP庫

3.parsedown(Markdown 解析庫)

專案網址:https://github.com/erusev/parsedown

一個小而美的PHP 的Markdown 解析函式庫。該庫提供了標準 Markdown 文字轉換成 HTML 字串功能,並擁有良好的文件。它的主檔案只有一個,除了 PHP 版本限制必須高於 5.3 外幾乎無依賴,可透過 composer 引入,也可以直接使用 Parsedown.php 檔案。此專案中使用大量正規表示式,可作為學習正規表示式的範例,並且有完整的單元測試。範例程式碼:

$Parsedown = new Parsedown();
echo $Parsedown->text(&#39;Hello _Parsedown_!&#39;); # 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(&#39;hello world&#39;);

// (Optional) Setup the paper size and orientation
$dompdf->setPaper(&#39;A4&#39;, &#39;landscape&#39;);

// 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 &#39;bootstrap.php&#39;;

// 新建文档
$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(
    &#39;"Learn from yesterday, live for today, hope for tomorrow. &#39;
        . &#39;The important thing is not to stop questioning." &#39;
        . &#39;(Albert Einstein)&#39;
);

6.easy-sms(簡訊傳送)

項目網址:https://github.com/overtrue/easy-sms

簡訊傳送PHP 元件。特點:

  • 支援目前市面多家服務商

  • #一套寫法相容於所有平台

  • 簡單配置即可靈活增減服務商

  • 內建多種服務商輪詢策略、支援自訂輪詢策略

use Overtrue\EasySms\EasySms;

$config = [
    // HTTP 请求的超时时间(秒)
    &#39;timeout&#39; => 5.0,

    // 默认发送配置
    &#39;default&#39; => [
        // 网关调用策略,默认:顺序调用
        &#39;strategy&#39; => \Overtrue\EasySms\Strategies\OrderStrategy::class,

        // 默认可用的发送网关
        &#39;gateways&#39; => [
            &#39;yunpian&#39;, &#39;aliyun&#39;,
        ],
    ],
    // 可用的网关配置
    &#39;gateways&#39; => [
        &#39;errorlog&#39; => [
            &#39;file&#39; => &#39;/tmp/easy-sms.log&#39;,
        ],
        &#39;yunpian&#39; => [
            &#39;api_key&#39; => &#39;824f0ff2f71cab52936axxxxxxxxxx&#39;,
        ],
        &#39;aliyun&#39; => [
            &#39;access_key_id&#39; => &#39;&#39;,
            &#39;access_key_secret&#39; => &#39;&#39;,
            &#39;sign_name&#39; => &#39;&#39;,
        ],
        //...
    ],
];

$easySms = new EasySms($config);

$easySms->send(13188888888, [
    &#39;content&#39;  => &#39;您的验证码为: 6379&#39;,
    &#39;template&#39; => &#39;SMS_001&#39;,
    &#39;data&#39; => [
        &#39;code&#39; => 6379
    ],

7.YOURLS(短網址產生)

#專案位址:https://github.com/YOURLS/YOURLS

【整理推薦】值得收藏的8個實用PHP庫

【整理推薦】值得收藏的8個實用PHP庫 ##完全免費的短網址服務。採用 PHP 編寫的短網址服務,它完全開源可自行搭建服務,支援資料統計、地理位置、視覺化等功能。

8.php-console(PHP 命令列應用程式庫)

【整理推薦】值得收藏的8個實用PHP庫專案位址:https://github.com/inhere/php-console

使用簡單,功能全面的PHP 命令列應用程式庫。提供控制台參數解析、命令運行、顏色風格輸出、 使用者資訊互動等功能

開班通知:

#php中文網第《22期PHP線上直播班》正式開始報名了!

教學形式:

1.零基礎開始,前端到後端,系統的學習!

###2.直播同步錄播,內部群,老師作業批改,輔導解答,督促學習#########限額活動:#########1.前50名報名同學,即送三部實戰課程,先到先得,送完為止! ######2.報名即贈送一套完整PHP課程(超值),課前學習! (限前10名)#########報名諮詢↓↓↓#########QQ報名:27220243(鐘老師)######微信報名:phpcn01(月月老師)###
陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn