WordPress at a glance

strip_fragment_from_url() WP 1.0

Strips the #fragment from a URL, if one is present.

✈ 1 time = 0.000035s = very fast | 50000 times = 0.20s = very fast

No Hooks.

Return

String. The altered URL.

Usage

strip_fragment_from_url( $url );
$url(string) (required)
The URL to strip.

Code of strip_fragment_from_url: wp-includes/canonical.php VER 5.0

<?php
function strip_fragment_from_url( $url ) {
	$parsed_url = @parse_url( $url );
	if ( ! empty( $parsed_url['host'] ) ) {
		// This mirrors code in redirect_canonical(). It does not handle every case.
		$url = $parsed_url['scheme'] . '://' . $parsed_url['host'];
		if ( ! empty( $parsed_url['port'] ) ) {
			$url .= ':' . $parsed_url['port'];
		}

		if ( ! empty( $parsed_url['path'] ) ) {
			$url .= $parsed_url['path'];
		}

		if ( ! empty( $parsed_url['query'] ) ) {
			$url .= '?' . $parsed_url['query'];
		}
	}

	return $url;
}

Related Functions

From tag: Link (URL)

More from category: Formatting

No comments
    Hello, !     Log In . Register