url::short PHP Method

short() static public method

Shortens an URL It removes http:// or https:// and uses str::short afterwards
static public short ( 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 short($url, $chars = false, $base = false, $rep = '…')
    {
        $url = str_replace('http://', '', $url);
        $url = str_replace('https://', '', $url);
        $url = str_replace('ftp://', '', $url);
        $url = str_replace('www.', '', $url);
        if ($base) {
            $a = explode('/', $url);
            $url = a::get($a, 0);
        }
        return $chars ? str::short($url, $chars, $rep) : $url;
    }

Usage Example

Beispiel #1
0
 public function __construct($mention)
 {
     $this->mention = $mention;
     $this->data = $mention->data['author'];
     $this->page = $mention->page;
     if (empty($this->data['url'])) {
         $this->data['url'] = $this->mention->data['url'];
     }
     if (empty($this->data['name'])) {
         $this->data['name'] = url::short(url::base($this->data['url']));
     }
     $this->field('url');
     $this->field('name');
 }
All Usage Examples Of url::short