sinevia/php-library-utils

PHP Library Utils

v3.8.0 2020-07-12 08:39 UTC

README

Gitpod Ready-to-Code

PHP Library Utils

The utility library provides multiple helper methods for PHP. These include methods for working with CSV, data, files, strings, etc.

No Dependencies Tests Gitpod Ready-to-Code

Installation

1. Via Composer

composer require sinevia/php-library-utils

2. Manually

Download from https://github.com/Sinevia/php-library-utils

Usage

\Sinevia\Utils::raiseMemoryLimits();

Classes and methods

Array Utils

  • columns splits the array into columns
\Sinevia\ArrayUtils::columns($array);
  • isAssoc checks whether an array is associative
\Sinevia\ArrayUtils::isAssoc($array);
  • toCsv converts an array to CSV. If the array is associative, the keys will be used for a header row
\Sinevia\ArrayUtils::toCsv($array, $forceQuotes=true);

Browser Utils

  • fingerprint
\Sinevia\BrowserUtils::fingerprint();

Csv Utils

  • write
\Sinevia\CsvUtils::write($filename, $array);

Data Utils

  • serialize
\Sinevia\DataUtils::serialize($data, $pass);
  • unserialize
\Sinevia\DataUtils::unserialize($data, $pass);

File Utils

Link Utils

  • getBaseUrl
\Sinevia\LinkUtils::getBaseUrl(); // ""
  • setBaseUrl
\Sinevia\LinkUtils::setBaseUrl("https://yahoo.com"); // ""
  • buildUrl
\Sinevia\LinkUtils::buildUrl("/", ['a'=>'A', 'b'=>'B']); // "/?a=A&b=B"

String Utils

  • between
\Sinevia\StringUtils::between("ABCDEFG","B","E"); // "CD"
  • camelize
  • endsWith
  • fixNewLines - fixes \r\n to \n
  • hasMinumumChars
  • hasLowercase
  • hasNumber
  • hasOnly
  • hasSubstring
  • hasUppercase
  • htmlEmailToText
  • isEmail
\Sinevia\StringUtils::isEmail("test@test"); // false
  • isJson
\Sinevia\StringUtils::isJson("ABC"); // false
  • leftFrom
  • maxWords
  • p2br
  • random
\Sinevia\StringUtils::rand(8); // "aBDhkDyD"
\Sinevia\StringUtils::rand(8, "ABC"); // "BABCCB"
  • regexSurround
  • regexReplace
  • rightFrom
  • slugify
  • snakify
  • splitId
  • startsWith
  • substringBetween
  • toArray
\Sinevia\StringUtils::toArray("ABC"); // ["A", "B", "C"]
  • toWords

Utils

  • arrayValueDelete
  • colorNameToHex
  • colorBrightness
  • forceFileDownload
  • forceFileDownloadFromContent
  • getTimeAgo
  • ip
\Sinevia\Utils::ip();
  • isCli
  • pagination
  • paginationReversed
  • pathToUrl
  • percents
  • redirectAndPostData
  • redirect
  • raiseMemoryLimits
  • rssToArray