When using URl’s you can break one if you don’t urlencode. var newurl = encodeURIComponent(url); PHP uses rawurlencode