If you want to avoid double encoding the links you can just use urldecode()
on both links, and then urlencode()
afterwards, as decoding a URL such as "https://www.cool.com/cool beans" would return the same value, whereas decoding "https://www.cool.com/cool%20beans" would return with the space. This leaves both links free to be encoded properly.
Alternatively, encoded characters could be scanned for using strpos()
function, e.g.
if ($pos = strpos($url, "%20") {
//Encoded character found
}
Ideally for this an array of common encoded characters would be scanned for, in the place of the "%20"