| 538 | * Strips the #fragment from a URL, if one is present. |
| 539 | * |
| 540 | * @param string $url The URL to strip. |
| 541 | * @return string The altered URL. |
| 542 | */ |
| 543 | function strip_fragment_from_url( $url ) { |
| 544 | $parsed_url = @parse_url( $url ); |
| 545 | if ( ! empty( $parsed_url['host'] ) ) { |
| 546 | // This mirrors code in redirect_canonical(). It does not handle every case. |
| 547 | $url = $parsed_url['scheme'] . '://' . $parsed_url['host']; |
| 548 | if ( ! empty( $parsed_url['port'] ) ) { |
| 549 | $url .= ':' . $parsed_url['port']; |
| 550 | } |
| 551 | $url .= $parsed_url['path']; |
| 552 | if ( ! empty( $parsed_url['query'] ) ) { |
| 553 | $url .= '?' . $parsed_url['query']; |
| 554 | } |
| 555 | } |
| 556 | |
| 557 | return $url; |
| 558 | } |
| 559 | |
| 560 | /** |