PHP Classes


Recommend this page to a friend!
  Classes of Ujah Chigozie peter   PHP String Functions Class   Download  
Role: Documentation
Content type: text/markdown
Description: Documentation
Class: PHP String Functions Class
General-purpose PHP functions to process strings
Author: By
Last change: Update
Date: 5 months ago
Size: 5,852 bytes


Class file image Download


Wrapped all basic reusable php function which I always on many of my project. This class might also be useful to beginners


Installation is super-easy via Composer:

composer require peterujah/php-functions


use \Peterujah\NanoBlock\Functions;
$func = new Functions();

Or extend the class and create your own new function like below.

class MyFunction extends \Peterujah\NanoBlock\Functions{
  public function __construct(){
  public function myFunction(){
    //do anything
  public static function myStaticFunction(){
    //do anything

And call initialize your custom class

$func = new MyFunction();

Available Static Methods

Make a random string/number

Functions::Random(10, Functions::INT);

Make a time ago from php timestamp, returns string


Generate a uuid string, returns string


Verify a uuid string return true or false


Verify email address is valid or not return true or false


Create a password hash key


Verify a password against hash key

Functions::Decrypt($password, $hash);

Check password strength

Functions::strongPassword($password, $minLength = 8,$maxLength = 16, $complexity=4);

Extract main domain name from subdomain

Functions::removeSubdomain(""); //returns

Calculate items average rating point

Functions::calcAverageRating($total_user_reviews, $total_rating_count);

Format number to money

Functions::Money($number, $fractional);

Discount from an (int, float, double) value by percentage

Functions::Discount(100, 10); // return 90

Increase interest of an (int, float, double) value by percentage

Functions::Interest(100, 10); //return 110

Fixed/Round a number to decimal

Functions::Fixed(12345.728836, 2);

Create a tag/badge from array

    ["php", "js", "css"], 

Create a button tag/badge from array

    ["php", "js", "css"], 

Returns user ip address


List time hours, returns array


Secure/format user input based on required data type

Functions::XSS("Rhd53883773", "int");

Formats Convert string characters to HTML entities

Functions::htmlentities($string, $encode);

Generate UPC product id

Functions::UPC($prefix = 0, $length = 12);

Generate EAN13 id

Functions::EAN($country = 615, $length = 13);

Copy files and folder to a new directory

Functions::copyFiles("path/from/file/", "path/to/file/");

Copy files and folder to a new directory

    "path/to/download/", //string filepath to download
    "", // string file name to download
    false // bool delete file after download is complete true or false

Truncate text based on length

    $text, //string text to truncate
    $length // int length to display

Base64 encode string for url passing


Base64 decode encoded url encoded string


Mask email address

    $email, // string email address
    "*" // character to mask with

Mask string by position

    $string, // string to mask
    "#", // character to mask with
    $position  //string position to mask left|right|center"

Determine password strength, if it meet all basic password rules such as 1. Does password meet the the minimum and maximum length? 2. Does password contain numbers? 3. Does password contain uppercase letters? 4. Does password contain lowercase letters? 5. Does password contain special characters?

Functions::strongPassword($password, $minLength, $maxLength);

Deletes files and folders

    "path/to/delete/file/", // path to delete files
    false // delete base file once sub files and folders has been deleted

Write new log line file

    "path/to/logs/", // string path to save logs
    "info.php",  // string log file name, use .php extension to secure log file from accessible in browser
    $data, // mixed log content
    $secure, // bool set true if file is using .php extension security method 
    $serialize, // bool serialize log content
    $replace // bool replace old log content

Save log a short hand replace parameter in Functions::writeLog

    "path/to/logs/", // string path to save logs
    "info.php",  // string log file name, use .php extension to secure log file from accessible in browser
    $data, // mixed log content
    $secure, // bool set true if file is using .php extension security method 
    $serialize, // bool serialize log content

Find log file

    "path/to/logs/info.php", //string filepath to log
    $unserialize // bool unserialize content if it was saved in serialize mode

Stripes unwanted characters from string and display text in new line in textarea

    $string, // string text to stripe unwanted characters
    $rules, // array rules array("[br/]" =>  "&#13;&#10;","<script>"    => "oops!",)
    $textarea // bool display text inside textarea