str::shorturl PHP Method

shorturl() static public method

Shortens an URL It removes http:// or https:// and uses str::short afterwards
static public shorturl ( string $url, integer $chars = false, boolean $base = false, string $rep = '…' ) : string
$url string The URL to be shortened
$chars integer The final number of characters the URL should have
$base boolean True: only take the base of the URL.
$rep string The element, which should be added if the string is too long. Ellipsis is the default.
return string The shortened URL
    static function shorturl($url, $chars = false, $base = false, $rep = '…')
    {
        return url::short($url, $chars, $base, $rep);
    }

Usage Example

Ejemplo n.º 1
0
 public function test_shorturl()
 {
     $sample = 'http://getkirby.com';
     $long = 'http://getkirby.com/docs/example/1/2/3';
     // without shortening
     $this->assertEquals('getkirby.com', str::shorturl($sample, false));
     // zero chars
     $this->assertEquals('getkirby.com', str::shorturl($sample, 0));
     // with shortening
     $this->assertEquals('getk…', str::shorturl($sample, 5));
     // with different ellipsis character
     $this->assertEquals('ge---', str::shorturl($sample, 5, false, '---'));
     // only keeping the base
     $this->assertEquals('getkirby.com', str::shorturl($long, false, true));
 }