PHPackages                             akintunde102/chocolate-php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. akintunde102/chocolate-php

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

akintunde102/chocolate-php
==========================

This project is to help php programmers have an easy time coding by having ready made functions for common and vital php operations

0181PHP

Since Dec 27Pushed 8y ago1 watchersCompare

[ Source](https://github.com/Akintunde102/chocolate-php)[ Packagist](https://packagist.org/packages/akintunde102/chocolate-php)[ RSS](/packages/akintunde102-chocolate-php/feed)WikiDiscussions master Synced 2w ago

READMEChangelogDependenciesVersions (11)Used By (0)

CHOCOLATE-PHP
=============

[](#chocolate-php)

**Name:** CHOCOLATE-PHP
**Contributors:** Akintunde Jegede
**TYPE:** LIBRARY
**Programmed with:** PHP
**Requires at least:** php 5.\*
**Major Dependency:** PHP
**License:** APACHE LICENSE 2.0
**License URI:**
**Composer Installation:** composer require akintunde102/chocolate dev-master

Short Summary:
==============

[](#short-summary)

This project is to help php programmers have an easy time coding by having ready made functions for common and vital php operations.

Description:
============

[](#description)

This library is meant to be a go-to-library for vital php functions. It's a continous project that will always welcome more functions to fulfil every "functional" needs a php developer could need. At the moment, it has 2 classes and about 15 vital php functions.

Further Description:
====================

[](#further-description)

These script has two major classes:

Chocolate Class:
----------------

[](#chocolate-class)

This class contains generic functions that performs all kinds of vital operations. It houses majority of the functions which are listed below:

#### shorten\_words($string, $wordsreturned)

[](#shorten_wordsstring-wordsreturned)

$string refers to the string to be shortened
\#wordsreturned refers to the number of words you want the word to be shortened to

#### if\_word\_present($string,$word)

[](#if_word_presentstringword)

$string represents the string to be checked
$word refers to the word to be checked

#### shorten\_by\_paragraph($string, $return)

[](#shorten_by_paragraphstring-return)

$string refers to the string to be shortened by paragraphs
$return refers to the number of paragraphs to be returned

#### text\_to\_url($in,$mth)

[](#text_to_urlinmth)

$in is the url or text to be formatted to url format such that the spaces are replaced with hyphen, e.g. i love you becomes i-love-you, you can append this to a url on your own
$mth can either be 'up' and 'down', 'up' is when its word to url, 'down' is from url to word

#### ossl\_encrypt($string) , ossl\_decrypt($string)

[](#ossl_encryptstring--ossl_decryptstring)

These functions help you to encrypt and decrypt a string using your own secret key . It will require that you have the openssl php extension \*\* installed $string refers to the string to be encrypted or decrypted

#### m\_encrypt($string) ,m\_decrypt($string)

[](#m_encryptstring-m_decryptstring)

These functions help you to encrypt and decrypt a string using your own secret key . It does not require that you have the openssl php extension \*\* installed $string refers to the string to be encrypted or decrypted

#### InitiateDownload($file,$ext)

[](#initiatedownloadfileext)

This is to initiate a direct download $file is the name of the file to be downloaded with the full path (e.g. 'image/popup.jpg') $ext is the name of the file extension e.g. 'jpg'

#### checkPHP()

[](#checkphp)

This is used to import PHPInfo() which shows all the sever details in a clickable file that is autogenrated as php.html

#### checkDomain($domain)

[](#checkdomaindomain)

This connects to several domain registries and returns the deatils of the specified domain in an autogenerated clickable file that contains the full WHOIS details

#### dirSize($dir)

[](#dirsizedir)

This gives the size of a whole folder/directory as specified as $dir. It returns the human readable format of the file size using the below function.

#### human\_filesize($bytes)

[](#human_filesizebytes)

This returns the human readable format of the size of a file as division could be messy when using performing direct division operations. This function takes care of that.

#### IsIPValid($ip)

[](#isipvalidip)

This is use to check if an ip is valid

#### synthaxPHP($code)

[](#synthaxphpcode)

This simply highlights php code. The $code represents the codes passed as a string

Below is an example of codes that can guide on how to initiate and use chocolate as a class

```
$a = new akintunde102\chocolatephp\chocolate;

$string = 'All versions of PHP that support namespaces support three kinds of aliasing or importing: aliasing a class name, aliasing an interface name, and aliasing a namespace name. PHP 5.6+ also allows aliasing or importing function and constant names.';
$wordsreturned = 20;

$a->shorten_words($string, $wordsreturned); //Function example, You can use other functions in the class in the same way

```

Courier Class
-------------

[](#courier-class)

This class is majorly for performing mail operations. Below is an example of codes that can guide on how to initiate and use the courier the class

```
$courier = new akintunde102\chocolatephp\courier;
$courier->sender = 'Example.Com '; //sender's email
$courier->recipient = $to; //recipient's email
$courier->subject = $title; //email title
$courier->message_text = $courier_txt; //the text format of the email
$courier->message_html = $sentence['full_html'];	//the html format of the email
if ($courier->send($courier)){echo 'Email sent';}; //then it gets sent

```

### Installation

[](#installation)

You can simply install this library by using composer.

If you don't know about composer, read about it [here](https://getcomposer.org/doc/01-basic-usage.md)

`composer require akintunde102/chocolate-php dev-master`

### Example

[](#example)

```

```

Testing
-------

[](#testing)

To test the libary before use, follow the steps below:

1. Go to vendor\\akintunde102\\chocolate-php\\example and copy the index.php
2. Paste the index.php to main directory
3. Then you can test the codes from your browser or command line as you may like

    ```
                                    OR

    ```
4. Create a file in the main directory and name it (for instance,'test.html')
5. Then copy the codes below into the file

```
