Back
Syntax
Study
Editor
Mode:
HTML
CSS
JavaScript
PHP
Reset
Run »
HTML / CSS / JS
<?php // Simulating namespaced classes in one file namespace App\Utilities { class StringHelper { public static function slugify(string $str): string { return strtolower(preg_replace("/[^a-z0-9]+/i", "-", trim($str))); } public static function truncate(string $str, int $len=50): string { return strlen($str) > $len ? substr($str,0,$len)."..." : $str; } } } namespace { use App\Utilities\StringHelper; echo "<p>" . StringHelper::slugify("Hello World! This is PHP") . "</p>"; echo "<p>" . StringHelper::truncate("This is a very long text that will be truncated", 20) . "</p>"; } ?>
Result
Open