PHP code example of junaidkhan / php-string-helper

1. Go to this page and download the library: Download junaidkhan/php-string-helper 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/ */

    

junaidkhan / php-string-helper example snippets




use JunaidKhan\StringHelper\StringHelper;

// Slugify
echo StringHelper::slugify('  Mastering PHP in 2025!  '); // master-php-in-2025

// Case conversions
echo StringHelper::toCamelCase('modern_php_tutorial');       // modernPhpTutorial
echo StringHelper::toSnakeCase('modernPhpTutorial');         // modern_php_tutorial
echo StringHelper::toKebabCase('modernPhpTutorial');         // modern-php-tutorial

// String checks
echo StringHelper::startsWith('FrameworkX', 'Frame');         // true
echo StringHelper::endsWith('SuperTool', 'Tool');             // true
echo StringHelper::contains('Debugging helps developers', 'help'); // true

// Truncate with suffix (text, maxLength, suffix, wordSafe, stripHtml, preserveHtml)
echo StringHelper::truncate('Mastering PHP in 2025!', 15, '...', true, false, false); // Mastering PHP...

// Limit words with suffix (text, wordLimit, suffix)
echo StringHelper::limitWords('Master PHP with real-world projects', 3, '...'); // Master PHP with...

// Reverse string (text)
echo StringHelper::reverse('Productivity'); // ytivitcudorP

// Remove special characters (text, preserveUnderscore, preserveDash, allowUnicode)
echo StringHelper::removeSpecialChars('[email protected]!', false, false, false); // Emailexamplecom

// Check valid JSON (string)
echo StringHelper::isJson('{"valid":true}'); // true