<?php
function a($strUrl) {
$strUrl = explode('/', $strUrl, 4);
$strUrl[3] = rawurlencode($strUrl[3]);
$strUrl[3] = str_replace(array('%2F', '%3F', '%3D', '%26', '%25'), array('/', '?', '=', '&', '%'), $strUrl[3]);
$strUrl = implode('/', $strUrl);
$strUrl = str_replace('&', '&', $strUrl);
return $strUrl;
}
function b($strUrl) {
return htmlspecialchars($strUrl, ENT_XML1, 'UTF-8');
}
$urls = array(
'http://www.example.com/',
'http://www.example.com/alias',
'http://www.example.com/alias.html',
'http://www.example.com/alias/page?foo=bar',
'http://www.example.com/alias?foo=bar&bar=foo',
'http://www.example.com:8080/alias',
'http://www.example.com:8080/alias?foo=bar&bar[bar]=foo',
);
foreach ($urls as $url) {
if (a($url) === b($url)) {
echo "✓\n";
echo $url."\n";
} else {
echo "✘\n";
echo $url."\n";
echo a($url)."\n";
echo b($url)."\n";
}
echo "\n";
}
- Output for 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.27, 8.2.0 - 8.2.17, 8.3.0 - 8.3.4
- ✓
http://www.example.com/
✓
http://www.example.com/alias
✓
http://www.example.com/alias.html
✓
http://www.example.com/alias/page?foo=bar
✓
http://www.example.com/alias?foo=bar&bar=foo
✓
http://www.example.com:8080/alias
✘
http://www.example.com:8080/alias?foo=bar&bar[bar]=foo
http://www.example.com:8080/alias?foo=bar&bar%5Bbar%5D=foo
http://www.example.com:8080/alias?foo=bar&bar[bar]=foo
preferences:
244.1 ms | 404 KiB | 282 Q