private static function Redirects::fixBadFragment in Hook Update Deploy Tools 8
Same name and namespace in other branches
- 7 src/Redirects.php \HookUpdateDeployTools\Redirects::fixBadFragment()
Alters url in the case where fragment incorrectly comes before the query.
Parameters
string $url: A URL to be checked and fixed (by reference).
1 call to Redirects::fixBadFragment()
- Redirects::parseCompleteUrl in src/
Redirects.php - Parses the url and creates some variations needed for redirects.
File
- src/
Redirects.php, line 376
Class
- Redirects
- Public methods for importing redirects.
Namespace
HookUpdateDeployToolsCode
private static function fixBadFragment(&$url) {
$fragment_location = strpos($url, '#');
$query_location = strpos($url, '?');
// Fragment can not come before query or it breaks parse_url().
if (!empty($fragment_location) && !empty($query_location) && $query_location > $fragment_location) {
// Fragment is in the wrong location, so move it.
$frag_length = $query_location - $fragment_location;
$fragment = substr($url, $fragment_location, $frag_length);
// Remove the fragment from the url.
$url = str_replace($fragment, '', $url);
// Put the fragment on the end.
$url = $url . $fragment;
}
}