Skip to content

Instantly share code, notes, and snippets.

@gharabaghi
gharabaghi / LaravelConvertOldRoutePatternToNewRoutePattern
Last active February 2, 2021 17:50
i used this script to convert laravel old style routes to new pattern. this works on phpstrom
in php storm, bring replace bar (ctrl + R) and check 'Regex' box and then enter these values:
in firt input (for find):
'([^ ']*)\\([^ ']*)@([^ ']*)'
in second input (for replace):
[Controllers\\$1\\$2::class, '$3']
@gharabaghi
gharabaghi / isHourBeforeNow
Created February 2, 2021 14:36
php check if hour and minute in form of H:i is before now
public static function isHourBeforeNow($hour)
{
$now = date('H:i');
$nowArray = explode(':', $now);
$hourArray = explode(':', $hour);
if ($nowArray[ 0 ] < $hourArray[ 0 ]) {
return false;
} else if ($nowArray[ 0 ] > $hourArray[ 0 ]) {
@gharabaghi
gharabaghi / verifyIranNationalCode
Created February 2, 2021 14:30
php verify national code for iran
public static function verifyNatCode($code)
{
if (!is_numeric($code) || strlen($code) > 10)
return false;
$tempInt = intval($code);
if ($tempInt == 0)
return false;
while (strlen($code) < 10) {
@gharabaghi
gharabaghi / formatCurrencyString
Created February 2, 2021 14:29
php format a currency numbered string
public static function formatCurrencyString($currency)
{
$currencySubStr1 = $currency;
$currencySubStr2 = '';
$dotPos = strpos($currency, '.');
if ($dotPos) {
$currencySubStr1 = substr($currency, 0, $dotPos);
$currencySubStr2 = substr($currency, $dotPos + 1, strlen($currency) - 1);
}
@gharabaghi
gharabaghi / generateRandomPassword
Created February 2, 2021 14:28
php generate password
public static function generateRandomPassword($length)
{
$signs = '_-!#@';
$signsLength = strlen($signs);
$numbers = '0123456789';
$numbersLength = strlen($numbers);
$alphs = 'abcdefghijklmnopqrstuvwxyx';
$alphsLength = strlen($alphs);
$signsCount = 1;
@gharabaghi
gharabaghi / isFloat
Created February 2, 2021 14:27
php- determin if a string is float or not.
public static function isFloat($numberString)
{
$regString = '/(^\d+\.\d+$|^\d+$)/';
return (bool)preg_match($regString, $numberString);
}
@gharabaghi
gharabaghi / makePaginationPageNumbers
Created February 2, 2021 14:25
php- make page numbers
public static function makePaginationPageNumbers($count, $perPage, $current, $offset)
{
$start = 1;
$hasPrevious = false;
$hasFirst = false;
$hasNext = false;
$hasLast = false;
$end = intval(floor($count / $perPage) + ($count % $perPage > 0 ? 1 : 0));