Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Zalgo Laravel Package

mdwheele/zalgo

Generate “Zalgo” glitch text in PHP/Laravel by corrupting strings with combining diacritics. Install via Composer, create a Soul, then summon a Zalgo instance with a Mood (e.g., soothed) to make text speak with chaotic effects.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation:

    composer require mdwheele/zalgo
    

    Add to composer.json under require-dev if only for testing.

  2. First Use Case:

    use Zalgo\Zalgo;
    
    $text = "Hello, world!";
    $zalgo = new Zalgo();
    echo $zalgo->apply($text); // Outputs: H̫̺̳e̬̜͎l̖̗̻̣̹̕l̴̘̝̱̰̠̩o̶̤̮̩̘,̨̻̪̖͔ ̣̭w̮̲̝̼̩̝͖o̸̰̩̖ͅr̞̘̫̩̼l̡͍̬͎̪̺͚͔d̢͓̪͕̜̰̠̦!
    
  3. Where to Look First:

    • Class: Zalgo\Zalgo (main class with apply() method).
    • Tests: /tests/ for edge cases (e.g., empty strings, special chars).
    • README: For visual examples of output.

Implementation Patterns

Core Workflow

  1. Basic Usage:

    $zalgo = new Zalgo();
    $result = $zalgo->apply($inputText);
    
    • Input: Plain text (string).
    • Output: Zalgo-transformed text (string).
  2. Integration with Laravel:

    • View Helpers:

      // app/Helpers/ZalgoHelper.php
      if (!function_exists('zalgo')) {
          function zalgo($text) {
              return app(Zalgo\Zalgo::class)->apply($text);
          }
      }
      

      Use in Blade:

      {{ zalgo('Your text here') }}
      
    • Middleware (for fun):

      namespace App\Http\Middleware;
      use Zalgo\Zalgo;
      
      class ZalgoMiddleware {
          public function handle($request, Closure $next) {
              $response = $next($request);
              $response->setContent(
                  app(Zalgo::class)->apply($response->getContent())
              );
              return $response;
          }
      }
      

      Register in app/Http/Kernel.php under $routeMiddleware.

  3. Conditional Application:

    $zalgo = new Zalgo();
    $shouldApply = true; // e.g., from config or user input
    echo $shouldApply ? $zalgo->apply($text) : $text;
    
  4. Testing:

    use Zalgo\Zalgo;
    use PHPUnit\Framework\TestCase;
    
    class ZalgoTest extends TestCase {
        public function testApply() {
            $zalgo = new Zalgo();
            $result = $zalgo->apply("Test");
            $this->assertNotEquals("Test", $result);
            $this->assertStringContainsString("̫̺̳", $result);
        }
    }
    

Gotchas and Tips

Pitfalls

  1. Performance:

    • Issue: The package is not optimized for large texts (e.g., processing entire HTML pages). Diacritics are applied character-by-character, which can be slow for long strings.
    • Workaround: Cache results or limit usage to small text snippets (e.g., error messages, notifications).
      $cachedZalgo = cache()->remember("zalgo_{$text}", now()->addHours(1), function() use ($text, $zalgo) {
          return $zalgo->apply($text);
      });
      
  2. HTML/UTF-8 Issues:

    • Issue: Applying Zalgo to HTML may break markup or cause rendering problems (e.g., diacritics interfering with CSS/JS).
    • Workaround: Restrict usage to plain-text contexts or sanitize output.
      $cleanHtml = strip_tags($zalgo->apply($dirtyHtml));
      
  3. Database Storage:

    • Issue: Storing Zalgo-text in a database may bloat storage and cause encoding issues.
    • Workaround: Store original text and apply Zalgo only when rendering.
  4. Randomness:

    • Issue: The package uses pseudo-random diacritic application. For consistent results (e.g., tests), avoid relying on exact output matches.
    • Workaround: Mock the Zalgo class in tests to return predictable output.

Debugging Tips

  1. Inspect Output: Use htmlentities() to visualize diacritics in logs:

    error_log(htmlentities($zalgo->apply("Test")));
    
  2. Disable Zalgo Temporarily: Extend the class to add a debug mode:

    class DebugZalgo extends Zalgo {
        public function apply($text, bool $debug = false) {
            return $debug ? $text : parent::apply($text);
        }
    }
    
  3. Character Limits: Test with edge cases:

    $zalgo->apply("");          // Empty string
    $zalgo->apply(str_repeat("a", 1000)); // Long string
    $zalgo->apply("😊");         // Emoji (may not work as expected)
    

Extension Points

  1. Custom Diacritics: Override the getDiacritics() method to add/remove symbols:

    class CustomZalgo extends Zalgo {
        protected function getDiacritics() {
            $diacritics = parent::getDiacritics();
            $diacritics[] = "̴"; // Add your own
            return $diacritics;
        }
    }
    
  2. Probability Control: Adjust the likelihood of applying diacritics by modifying the internal logic (e.g., reduce the randomness factor):

    class LightZalgo extends Zalgo {
        protected function applyDiacritic($char) {
            if (mt_rand(0, 2) === 0) { // 33% chance (default is ~50%)
                return $char . $this->getRandomDiacritic();
            }
            return $char;
        }
    }
    
  3. Laravel Service Provider: Bind the package to the container for easy dependency injection:

    // app/Providers/AppServiceProvider.php
    public function register() {
        $this->app->singleton(Zalgo\Zalgo::class, function() {
            return new Zalgo\Zalgo();
        });
    }
    

Config Quirks

  • No Configuration File: The package has no built-in config. All behavior is hardcoded in the Zalgo class.
  • Thread Safety: The class is stateless and thread-safe, but randomness may vary across requests.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
directorytree/privacy-filter-classifier
directorytree/privacy-filter
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
22h/doctrine-garbage-collection-bundle
agtp/agtp-php
agtp/mod-php
splash/sonata-admin
splash/metadata
splash/openapi
splash/scopes
splash/toolkit
testo/output-teamcity
testo/bridge-symfony
spatie/flare-daemon-runtime