🎉 Exercism Research is now launched. Help Exercism, help science and have some fun at research.exercism.io 🎉
Avatar of julian13

julian13's solution

to Pangram in the PHP Track

Published at Dec 10 2020 · 0 comments
Test suite

Determine if a sentence is a pangram. A pangram (Greek: παν γράμμα, pan gramma, "every letter") is a sentence using every letter of the alphabet at least once. The best known English pangram is:

The quick brown fox jumps over the lazy dog.

The alphabet used consists of ASCII letters a to z, inclusive, and is case insensitive. Input may contain non-ASCII symbols, but it is only necessary to check whether each letter in the English alphabet is present.

Running the tests

  1. Go to the root of your PHP exercise directory, which is <EXERCISM_WORKSPACE>/php. To find the Exercism workspace run

     % exercism debug | grep Workspace
  2. Get PHPUnit if you don't have it already.

     % wget --no-check-certificate https://phar.phpunit.de/phpunit.phar
     % chmod +x phpunit.phar
  3. Execute the tests:

     % ./phpunit.phar pangram/pangram_test.php


Wikipedia https://en.wikipedia.org/wiki/Pangram

Submitting Incomplete Solutions

It's possible to submit an incomplete solution so you can see how others have completed the exercise.



class PangramTest extends PHPUnit\Framework\TestCase
    public static function setUpBeforeClass() : void
        require_once 'pangram.php';

    public function testSentenceEmpty() : void

    public function testPangramWithOnlyLowerCase() : void
        $this->assertTrue(isPangram('the quick brown fox jumps over the lazy dog'));

    public function testMissingCharacterX() : void
        $this->assertFalse(isPangram('a quick movement of the enemy will jeopardize five gunboats'));

    public function testAnotherMissingCharacterX() : void
        $this->assertFalse(isPangram('the quick brown fish jumps over the lazy dog'));

    public function testPangramWithUnderscores() : void

    public function testPangramWithNumbers() : void
        $this->assertTrue(isPangram('the 1 quick brown fox jumps over the 2 lazy dogs'));

    public function testMissingLettersReplacedByNumbers() : void
        $this->assertFalse(isPangram('7h3 qu1ck brown fox jumps ov3r 7h3 lazy dog'));

    public function testPangramWithMixedCaseAndPunctuation() : void
        $this->assertTrue(isPangram('\Five quacking Zephyrs jolt my wax bed.\\'));

    public function testPangramWithNonAsciiCharacters() : void
        $this->assertTrue(isPangram('Victor jagt zwölf Boxkämpfer quer über den großen Sylter Deich.'));

    public function testMissingLetterReplacedWithUpperCaseCharacter() : void
        $this->assertFalse(isPangram("Tthe quick brown fo jumps over the lazy dog"));

 * isPangram
 * @param  mixed $string
 * @return void
function isPangram(string $string)
    $chars = range('a','z');
    $found = 0;
    $countChars = count($chars);
    $checked = [];
    foreach($chars as $char) {
        if (stripos($string, $char) !== false && !in_array($char, $checked)) {
            $checked[] = $char;

    return ($found === $countChars ? true : false);

Community comments

Find this solution interesting? Ask the author a question to learn more.

What can you learn from this solution?

A huge amount can be learned from reading other people’s code. This is why we wanted to give exercism users the option of making their solutions public.

Here are some questions to help you reflect on this solution and learn the most from it.

  • What compromises have been made?
  • Are there new concepts here that you could read more about to improve your understanding?