PHP code example of effectra / to-string

1. Go to this page and download the library: Download effectra/to-string library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

effectra / to-string example snippets


use Effectra\ToString\TextToString;

$textToString = new TextToString('Hello, World!');

// Converts a string to uppercase.
echo $textToString->toUppercase(); // Output: HELLO, WORLD!

// Converts a string to lowercase.
echo $textToString->toLowercase(); // Output: hello, world!

// Strips HTML and PHP tags from a string.
$textToString->setValue('<p>Hello, <b>World!</b></p>');
echo $textToString->strip(); // Output: Hello, World!

// Converts a string to a URL-friendly slug.
$textToString->setValue('Hello, World!');
echo $textToString->textToSlug(); // Output: hello-world

// Generates a random text of specified length.
echo $textToString->generateRandomText(8); // Output: e.g. C4rN1QX7

use Effectra\ToString\ArrayToString;

$arrayToString = new ArrayToString(['apple', 'banana', 'cherry']);

// Converts an array to a string representation.
echo $arrayToString->array(); // Output: ['apple', 'banana', 'cherry'] (formatted)

// Converts an array to a string by joining its elements with a separator.
echo $arrayToString->arrayToText(','); // Output: apple,banana,cherry

// Converts an array to a URL-friendly slug by joining its elements.
echo $arrayToString->arrayToSlug(); // Output: apple-banana-cherry

// Converts an array to a key-value pair string representation.
$arrayToString->setValue(['name' => 'John', 'age' => 25]);
echo $arrayToString->arrayToTextKeyValue(); 
/* Output:
name: John,
age: 25,
*/

use Effectra\ToString\DateToString;

$dateToString = new DateToString(3600); // 3600 seconds (1 hour)

// Formats a time value in seconds into HH:MM:SS format.
echo $dateToString->formatTime(); // Output: 01:00:00

// Formats a timestamp into YYYY-MM-DD format.
$dateToString->setValue(time());
echo $dateToString->formatDate(); // Output: e.g. 2023-05-13