此包的最新版本(v1.2.17)没有可用的许可信息。

live-controls 的 utils 包

v1.2.17 2024-09-26 18:26 UTC

This package is auto-updated.

Last update: 2024-09-26 18:27:15 UTC


README

Release Version Packagist Version

LiveControls 的工具包。一些其他的 LiveControls 包将依赖于这个库。

用法

数组

array_get

$array['val1' => 'Value1', 'val2' => 'Value2'];
echo array_get('val1', $array); // 'Value1'
echo array_get('val3', $array); // null
echo array_get('val3', $array, 'no_value'); // 'no_value'

array_remove

$array['val1' => 'someValue', 'val2' => 'someOtherValue'];
array_remove('val1', $array);
echo $array; //['val2' => 'someOtherValue']

array_remove_value

$array ['someValue', 'someOtherValue'];
array_remove_value('someValue', $array);
echo $array; //['someOtherValue']

array_has_duplicates

$array['someValue', 'someOtherValue'];
echo array_has_duplicates($array); //returns false
$array2['key1' => 'someValue', 'key2' => 'someValue'];
echo array_has_duplicates($array2); //returns true
$array3['1984', 1984];
echo array_has_duplicates($array3, true); //returns false, because type of value 0 is different than from value 1
$array4[1984, 1984];
echo array_has_duplicates($array4, true); //returns true, because type of value 0 and value 1 are identical

array_get_duplicates

$array['someValue', 'someOtherValue'];
echo array_get_duplicates($array); //returns an empty array
$array2['key1' => 'someValue', 'key2' => 'someValue'];
echo array_get_duplicates($array2); //returns an array ['someValue']
$array3['1984', 1984];
echo array_get_duplicates($array3, true); //returns an empty array, because type of value 0 is different than from value 1
$array4[1984, 1984];
echo array_get_duplicates($array4, true); //returns an array [1984], because type of value 0 and value 1 are identical

BBCodes

有效的 bb 标签

  • [b][/b]
  • [i][/i]
  • [s][/s]
  • [u][/u]
  • [img][/img]
  • [img=varxvar][/img]
  • [center][/center]
  • [justify][/justify]
  • [right][/right]
  • [ul][/ul]
  • [ol][/ol]
  • [li][/li]
  • [url=][/url]
  • [url][/url]
  • [email=][/email]
  • [size=][/size]
  • [color=][/color]
  • [hr]
  • [sub][/sub]
  • [sup][/sup]

博客

estimatedReadingTime

根据每分钟单词数计算文本的预估阅读时间

$text = "This is a text with 400 words [...]"; //Imagine this text as 400 words long
echo estimatedReadingTime($text); //Would return 2 (minutes) as the default words per minute rate is 200
echo estimatedReadingTime($text, 100); //Would return 4 (minutes) as the second parameter of the function acts as words per minute 

Utils

countNumber

计算一个数字中包含的数字数量

$var = 1234;
echo countNumber($var); //'4'

calculateDaysInMonth

计算特定月份中从 $fromDay 到 $toDay 之间的天数

echo calculateDaysInMonth(0,5,11,2022); //returns the days in month as integer

number2Text

将分转换成其文本形式。需要 NumberFormatter 才能工作!

echo number2Text(100, 'pt_BR'); //returns the text representation of the number by its locale

leadingZeros

给一个数字添加前导零

echo leadingZeros(10, 4, false); //returns 0010
echo leadingZeros(10, 1, true); //throws exception because third parameter (isMax) is true and the number has more than 1 digit (second parameter {length})

number2Currency

将数字转换成其货币形式。需要 NumberFormatter 才能工作!

echo number2Currency(1000.20, 'pt_br', 'USD'); //returns $1.000,20

array2String

将数组转换为带有分隔符的字符串

echo array2String(['a','b','c'], '; '); //returns a; b; c

isNullOrEmpty

检查字符串是否为空或为 null

echo isNullOrEmpty(' '); //returns true

calculateFormulas

TODO,不要使用,因为它处于测试阶段!

toInteger

移除字符串中的所有非数字字符和前导零,并返回一个整数

echo toInteger('a1234'); //returns 1234
echo toInteger('a01234'); //IMPORTANT, this would also return 1234 as an integer cant start with 0. In this case use toNumeric()

toNumeric

移除字符串中的所有非数字字符,并返回一个整数或字符串(如果它以 0 开头)

echo toNumeric('a01234'); //returns a string 01234
echo toNumeric('a1234'); //returns an integer 1234

stringContains

检查字符串是否包含某个特定的针

echo stringContains('Test', 'T'); //returns true
echo stringContains('Test', 'Q'); //returns false

isValidCPF

检查 CPF 号码是否有效

echo isValidCPF('UM_CPF_VALIDO'); //returns true if cpf is valid

isValidCNPJ

检查 CNPJ 号码是否有效

echo isValidCNPJ('UM_CNPJ_VALIDO'); //returns true if cnpj is valid

toLatin

将字符串转换为仅包含拉丁字符的字符串

echo toLatin('càdé'); //returns cade

importCSV

从文件导入 CSV,并返回一个带有标题的数组作为第一行

echo importCSV('test.csv'); //returns the content of the file test.csv as array with its first line as header