YsUtil
YsUtil is an utilities class for yii framework, also a collection of function snippets that make your web application building job easier. As YeeBase is using YsUtil, it is an integral part of it too.
Install thru composer: https://packagist.org/packages/exiang/ys-util
composer require exiang/ys-util
Email Related
sendMail($receivers, $subject, $message, $params, $sendOnBehalf='')
Required PHPMailer
composer package.
logSentMail($mailObj, $mailLogPath)
String Manipulation
html2text($html)
Required Html2Text
composer package. Change HTML to plain text string. For example, use in generate alternate text version of email content.
splitFullName2FirstLast($name)
Return array('firstName'=>$firstName, 'lastName'=>$lastName)
by spliting any full name string you insert, e.g.: Allen Tan.
generateUUID()
Generate Universal Unique ID which is useful for code
. Internally try to generate thru com_create_guid
. If this PHP function not found, then it fallback to use mt_rand
method.
slugify($text)
Turn any text into URL friendly slug format thru series of operations like: trim, lowercase, replace non letter or digits by -, remove unwanted characters and transliterate utf-8.
generateRandomKey($max=5, $min=4, $mode='alphanumeric')
Generate a random key code at specific length and mode (alphabet only or number only, or both)
$mode:
alphanumeric
alpha
numeric
generateRandomPassword($max='8', $min='8', $lowerCase=true)
nl2space($string)
truncate($string='', $limit=100, $pad='...')
mbWordWrap($string, $width=75, $break="\n", $cut=false)
widerKeyword($keyword)
null2empty($string)
strPutCsv($input, $delimiter = ',', $enclosure = '"')
Array Manipulation
yskrsort($array)
string2Array($str, $separator=',')
generateArrayRange($start, $stop, $mode='1d')
convertToKeyValueArray($array, $code='key', $title='title')
convert1dTo2dArray($array)
Data Format Related
decimal2Bui($decimal)
Convert decimal to base unit integer
bui2Decimal($bui)
Convert base unit integer back to decimal
m2km($meter, $showUnit=false)
Convert meter to kilometer
formatByte($bytes, $unit = "MB", $decimals = 2)
ssNum2Alpha($n)
Convert spreadsheet's column number to alphabet. Example:
1 -> A
26 -> Z
27 -> AA
isMd5($string)
Return true
if a string is MD5 encoded format, else false
.
isSha1($string)
Return true
if a string is SHA1 encoded format, else false
.
isAlphaNumeric($input)
Return true
if a string is in alpha numeric (a-z, A-Z, 0-9 only) format, else false
.
isEmailAddress($input)
Return true
if a string is a valid email, else false
. Internally using PHP filter_var
FILTER_VALIDATE_EMAIL
isJson($string)
Return true
if a string is valid JSON format, else false
. Internally it used json_decode
to check.
File System Related
getMimeType($filename)
listDir($dir, $recur = true)
fileGetBinary($file)
getFileName($filename)
getFileExtension($filename)
Date Time Related
timezone2offset($name)
convertTimezone($timestamp, $toTimezone, $fromTimezone='GMT')
take a timestamp from timezone A (preset to GMT) and convert to timezone B
timeElapsed($timestamp, $precision=5)
Time elapsed to human readable format (e.g. 2 days 45 min ago).
getWeekInMonth($timestamp, $rollover='sunday')
calculateAge($timestamp = 0, $now = 0)
monthNumber2Name($number, $format='F')
dateDiff($interval, $datefrom, $dateto, $using_timestamps = false)
$interval:
yyyy - Number of full years
q - Number of full quarters
m - Number of full months
y - Difference between day numbers (eg 1st Jan 2004 is "1", the first day. 2nd Feb 2003 is "33". The datediff is "-32".)
d - Number of full days
w - Number of full weekdays
ww - Number of full weeks
h - Number of full hours
n - Number of full minutes
s - Number of full seconds (default)
Network & Cloudflare Related
ipInRange($ip, $range)
getRequestIP()
isCloudflare()
cloudflareCheckIP($ip)
cloudflareRequestsCheck()
Others
toChinaseNum($num)
Last updated
Was this helpful?