PHP code example of rodrigomanara / alpha

1. Go to this page and download the library: Download rodrigomanara/alpha 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/ */

    

rodrigomanara / alpha example snippets



Manara\Alpha\Alpha;

$alpha = new Alpha();

// Analyze a string
$string = "Hello World 123!";

// Count different character types
$vowels = $alpha->checkVowels($string);       // Returns: 3 (e, o, o)
$consonants = $alpha->checkConsonates($string); // Returns: 7 (H, l, l, W, r, l, d)
$numbers = $alpha->checkNumber($string);      // Returns: 3 (1, 2, 3)
$special = $alpha->noalpha($string);          // Returns: 2 (space, !)
$uppercase = $alpha->upper($string);          // Returns: 2 (H, W)
$lowercase = $alpha->lower($string);          // Returns: 8 (e, l, l, o, o, r, l, d)

// Get average word length
$average = $alpha->calculateWordLetterAverage("hello world php"); // Returns: 5

// Retrieve collected results
$results = $alpha->getAll();  // Get all collected data
print_r($results);

$alpha = new Alpha();

// Count vowels
$vowelCount = $alpha->checkVowels("javascript");
// Result: 3 (a, a, i)

// Count consonants
$consonantCount = $alpha->checkConsonates("javascript");
// Result: 7 (j, v, s, c, r, p, t)

// Count numeric digits
$digitCount = $alpha->checkNumber("abc123def456");
// Result: 6 (1, 2, 3, 4, 5, 6)

$alpha = new Alpha();

$upperCount = $alpha->upper("PHPisFun");      // Returns: 3 (P, H, P)
$lowerCount = $alpha->lower("PHPisFun");      // Returns: 5 (i, s, u, n)

$alpha = new Alpha();

// Count non-alphanumeric characters (spaces, punctuation, symbols)
$specialCount = $alpha->noalpha("Hello, World!");
// Result: 2 (comma, space, exclamation)

$alpha = new Alpha();

// Calculate average characters per word (rounded up)
$average = $alpha->calculateWordLetterAverage("I am testing this library");
// Words: I(1), am(2), testing(7), this(4), library(7)
// Average: (1+2+7+4+7)/5 = 4.2 → rounds to 5

$alpha = new Alpha();

// Analyze and store results
$alpha->checkVowels("hello");
$alpha->checkNumber("abc123");

// Retrieve specific results
$vowels = $alpha->get('vowels');        // Array of vowels found
$numbers = $alpha->get('numbers');      // Array of numbers found

// Get all collected results
$allResults = $alpha->getAll();
// Output:
// [
//     'vowels' => ['e', 'o', 'o'],
//     'numbers' => ['1', '2', '3']
// ]


use Manara\Alpha\Alpha;

$alpha = new Alpha();
$input = "PHP 8.1 is awesome!";

// Perform complete analysis
$vowels = $alpha->checkVowels($input);
$consonants = $alpha->checkConsonates($input);
$numbers = $alpha->checkNumber($input);
$special = $alpha->noalpha($input);
$uppercase = $alpha->upper($input);
$lowercase = $alpha->lower($input);

// Display summary
echo "Analysis of: '$input'\n";
echo "Vowels: $vowels\n";
echo "Consonants: $consonants\n";
echo "Numbers: $numbers\n";
echo "Special Characters: $special\n";
echo "Uppercase: $uppercase\n";
echo "Lowercase: $lowercase\n";

// View detailed results
$results = $alpha->getAll();
echo "Detailed Results:\n";
print_r($results);

// Lowercase vowels only:
$alpha->checkVowels("HELLO");      // Returns: 0
$alpha->checkVowels("hello");      // Returns: 2 (e, o)

// Use lower() for lowercase letter counting:
$alpha->lower("HeLLo");            // Returns: 2 (e, o)
$alpha->upper("HeLLo");            // Returns: 3 (H, L, L)