wpseek.com
Bazujące na WordPress narzędzie wyszukiwania dla deweloperów i twórców motywów.



url_shorten › WordPress Function

Od1.2.0
Przestarzałyn/a
url_shorten ( $url, $length = 35 )
Parametry: (2)
  • (string) $url URL to shorten.
    Wymagane: Tak
  • (int) $length Optional. Maximum length of the shortened URL. Default 35 characters.
    Wymagane: Nie
    Domyślny: 35
Powrót:
  • (string) Shortened URL.
Zdefiniowane na:
Codex:
Dziennik zmian:
  • 4.4.0

Shortens a URL, to be used as link text.



Źródło

function url_shorten( $url, $length = 35 ) {
	$stripped  = str_replace( array( 'https://', 'http://', 'www.' ), '', $url );
	$short_url = untrailingslashit( $stripped );

	if ( strlen( $short_url ) > $length ) {
		$short_url = substr( $short_url, 0, $length - 3 ) . '…';
	}
	return $short_url;
}