If I want to create a URL using a variable I have two choices to encode the string. urlencode() and rawurlencode().
urlencode()
rawurlencode()