wpseek.com
WordPress开发者和主题制作者的搜索引擎



strip_fragment_from_url › WordPress Function

Since4.4.0
已弃用n/a
strip_fragment_from_url ( $url )
参数:
  • (string) $url The URL to strip.
    Required: Yes
返回:
  • (string) The altered URL.
定义在:
文档:

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



源码

function strip_fragment_from_url( $url ) {
	$parsed_url = wp_parse_url( $url );

	if ( ! empty( $parsed_url['host'] ) ) {
		$url = '';

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

		$url .= '//' . $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;
}