panduanvip / helpers
文本或字符串操作
1.0.0
2021-07-06 00:24 UTC
This package is auto-updated.
Last update: 2024-09-06 07:10:56 UTC
README
我常用的一些PHP函数的集合
安装
composer require panduanvip/helpers
用法
<?php include 'vendor/autoload.php'; use PanduanVIP\Helpers\Please;
获取网页内容
echo Please::getWebContent('https://google.com');
结果
return html page from google.com
获取多个网页内容
echo Please::getWebContents(['https://google.com', 'https://yahoo.com']);
结果
return html pages from google.com dan yahoo.com
创建随机字符串
echo Please::createRandomString();
结果
7y2cNs
从数组中随机选择一个项目
$array = ['Pen', 'Book', 'Laptop', 'Bus', 'Plane', '']; $result = Please::pickOneRandom($array);
结果
Book
修剪分隔符附近的空格
$string = "Gunadarma , Jayabaya, Pancasila,,"; $result = Please::trimAllSpaces($string, ',');
结果
Gunadarma,Jayabaya,Pancasila
从spintax创建句子
$string = "{green|blue|yellow} bird is sitting {there|over there|on the ground}."; $result = Please::createSpintax($string);
结果
blue bird is sitting on the ground.
根据换行符将字符串转换为数组
$string = <<<test Example of string spanning multiple lines using heredoc syntax. test; $result = Please::explodeNewLine($string);
结果
['Example of string', 'spanning multiple lines', 'using heredoc syntax.']
从段落创建摘要
$string = "PHP is a general-purpose scripting language especially suited to web development. It was stringly created by Danish-Canadian programmer Rasmus Lerdorf in 1994. The PHP reference implementation is now produced by The PHP Group."; $result = Please::createExcerpt($string, 50);
结果
PHP is a general-purpose scripting language...
将双空格替换为单空格
$string = "Lorem ipsum dolor sit amet, consectetur adipiscing elit"; $result = Please::removeDoubleSpace($string);
结果
Lorem ipsum dolor sit amet, consectetur adipiscing elit
获取两个字符串之间的字符串
$string = "This is my dog!"; $result = Please::getStringBetween($string, "my", "!");
结果
dog
为创建URL别名清理字符串
$string = "красивые сакуры"; $result = Please::createSlug($string);
结果
красивые-сакуры