silkyland/sawasdee
Composer 安装命令:
composer require silkyland/sawasdee
包简介
Sawasdee, a miscellaneous tools for Thai language
关键字:
README 文档
README
Sawasdee, A miscellaneous library for number, words translator to Thai reading style including with Thai currency, date and time, Thai unit and also included Thai SEO URL. Sawasdee comes with easy to use PHP style and powerful with documentation.
Contributors
What's Sawasdee can do?
Sawasdee can translate number to Thai words reading style comes with:
- Translate DateTime to Thai DateTime e.g. "08/16/2015" convert to "16 สิงหาคม 2515" or "๑๖ สิงหาคม ๒๕๕๘" or any format you need
- Translate Thai currency e.g. "121.25" convert to "หนึ่งร้อยยี่สิบเอ็ดบาทยี่สิบห้าสตางค์" or input "215" will convert to "สองร้อยสิบห้าบาทถ้วน"
- Translate Thai Unit e.g. "999.99" convert to "เก้าร้อยเก้าสิบเก้าจุดเก้าเก้า"
- Convert word to url style e.g. "Boostrap ครองแชมป์ css framework ที่ดีที่สุด 100%" to "Boostrap-ครองแชมป์-css-framwork-ที่ดีที่สุด-100-เปอร์เซนต์"
Require
- PHP Version 5.4 or above
Installation
Via composer
Simply add a dependency on silkyland/sawasdee to your project's composer.json file if you use Composer to manage dependencies of your project. You can add code below to your composer.json file.
{
"require-dev": {
"silkyland/sawasdee": "1.*"
}
}
Or you can use command-line to add silkyland\sawasdee package too by use this command.
composer require silkyland/sawasdee
Via Download
Download zip file and exact to any folder you need in your project.
Usage
Thai date and time
By using "toThaiDateTime()" function you can input parameter string $date_input, bool $format, bool $short_month, bool $thai_numberic and bool $buddhist_year:
$sawasdee = new Sawasdee;
Basic using it will product default format like "date|month|buddhist year| |hourนาฬิกา|minuteนาที|secondวินาที"
echo $sawasdee->toThaiDateTime('08/17/2015 09:50'); // 17สิงหาคม2558 9นาฬิกา50นาที00วินาที
You can custom format with these words : %d (date), %m (month), %y (year), %h (hour), %i (minute), %s (second).
echo $sawasdee->toThaiDateTime('08/17/2015 09:50', '%d %m %y'); // 17 สิงหาคม 2558 echo $sawasdee->toThaiDateTime('08/17/2015 09:50', '%hชั่วโมง %iนาที %sวินาที'); // 9ชั่วโมง 5นาที 0วินาที echo $sawasdee->toThaiDateTime('08/17/2015 09:50', 'เมื่อเวลา %h %m ของวันที่ %d เดือน %m พ.ศ. %y'); // เมื่อเวลา 09:50 ของวันที่ 17 เดือน สิงหาคม พ.ศ. 2558 echo $sawasdee->toThaiDateTime('08/17/2015 09:50', 'ทุกๆวันที่%dของเดือน%mเป็นวันเกิดฉัน'); // ทุกๆวันที่17เดือนสิงหาคมเป็นวันเกิดฉัน //Or you can use default format by input "false" to second parameter echo $sawasdee->toThaiDateTime('08/17/2015 09:50', false); // 17สิงหาคม2558 9นาฬิกา50นาที00วินาที
By default short term of Thai month is turn to "false" that mean it will appear month name in full term. If you need a short term you need to use "true" in third parameter like this :
echo $sawasdee->toThaiDateTime('08/17/2015 09:50', '%d %m %y', true); // 17 ส.ค. 2558
If you need Thai alphabet numberic for output number just use "true" in the 4th parameter :
echo $sawasdee->toThaiDateTime('08/17/2015 09:50', '%d %m %y', true, true); // ๑๗ ส.ค. ๒๕๕๘
Because Thailand use buddhist year and Sawasdee turn to buddhist year by default, If you need to change, you can also use "false" for AD (Anno Domini) format :
echo $sawasdee->toThaiDateTime('08/17/2015 09:50', '%d %m %y', true, false, false); // 17 ส.ค. 2015
Thai currency reading style
To convert number to reading style you need to input number such as "456", 12500021, or "15.25" and it will return Thai number reading style back. Sure! it also already include "บาท (Bath)" and "สตางค์ (Satang)" in words its return.
echo $sawasdee->readThaiCurrency(0); // ศูนย์บาท echo $sawasdee->readThaiCurrency(125); // หนึ่งร้อยยี่สิบห้าบาทถ้วน echo $sawasdee->readThaiCurrency(125.00); // หนึ่งร้อยยี่สิบห้าบาทถ้วน echo $sawasdee->readThaiCurrency(125.25); // หนึ่งร้อยยี่สิบห้าบาทยี่สิบห้าสตางค์
Thai unit reading style
In Thai language unit reading such as metre, kilometre, gram, kilogram, celsius etc. Are read different from Thai currency in decimal point. "readThaiUnit()" function is useful to read unit in Thai style.
echo $sawasdee->readThaiUnit(0); // ศูนย์ echo $sawasdee->readThaiUnit(125); // หนึ่งร้อยยี่สิบห้า echo $sawasdee->readThaiUnit(125.00); // หนึ่งร้อยยี่สิบห้า echo $sawasdee->readThaiUnit(125.25); // หนึ่งร้อยยี่สิบห้าจุดสองห้า echo $sawasdee->readThaiUnit(125.25).' กิโลเมตร'; // หนึ่งร้อยยี่สิบห้าจุดสองห้ากิโลเมตร
Thai URL SEO Friendly
To convert words to url style you need to use toThaiUrl() function
echo $sawasdee->toThaiURL('sawasdee ไลบราลี่ภาษา PHP ที่สามารถใช้งานได้ง่ายที่สุด'); // sawassdee-ไลบราลี่ภาษา-php-ที่สามารถใช้งานได้ง่ายที่สุด echo 'http://devded.com/'.$sawasdee->toThaiURL('sawasdee ไลบราลี่ภาษา PHP ที่สามารถใช้งานได้ง่ายที่สุด'); // http://devded.com/sawassdee-ไลบราลี่ภาษา-php-ที่สามารถใช้งานได้ง่ายที่สุด echo 'http://devded.com/'.$sawasdee->toThaiURL('sawasdee ไลบราลี่ภาษา PHP ที่สามารถใช้งานได้ง่ายที่สุด').'html'; // http://devded.com/sawassdee-ไลบราลี่ภาษา-php-ที่สามารถใช้งานได้ง่ายที่สุด.html
silkyland/sawasdee 适用场景与选型建议
silkyland/sawasdee 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 243 次下载、GitHub Stars 达 16, 最近一次更新时间为 2015 年 08 月 17 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「sawasdee」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 silkyland/sawasdee 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 silkyland/sawasdee 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 243
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 17
- 点击次数: 14
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-08-17