Phill M.
Phill M.

Reputation: 21

Preserve white space in URL with PHP

I am stuck big time on this problem and google has been of no help to me so far. I am trying to find a way to preserve white space in a URL with moderate to no luck.

I have a form that needs to gather post data, mail it, and then append the post data to the URL as comma separated value and redirects them to a page where they download a product.

Once the user presses download that page reads the data in the URL and applies it to a billing invoice (the program is billed on time usage).

A simplified example:

$addressOne = $_POST['addressOne'];
$newURL = "http://subdomain.domain.com/connectnow=on?" . ", Address1=" . $addressOne;
If(mailSent) {
    header("Location: $newURL")
}

There are a lot more values obviously, but the address is one of the areas that I am having this issue.

I have tried doing something like:

$newURL = str_replace("  ", " ", $newURL);

That worked as far as preserving the whitespace in the URL visually, but when the program that gets downloaded reads the URL it replaces the   as %C2%.

I have also tried:

$newURL = str_replace("  ", " \40", $newURL);

That made the spaces in the URL convert back to %20.

Any guidance would be appreciated.

Upvotes: 2

Views: 1549

Answers (1)

mend3
mend3

Reputation: 516

URL:

www.site.com/my spaces preserved/

urlencode()

www.site.com%2Fmy+spaces+preserved%2F

urldecode()

www.site.com/my spaces preserved/

Upvotes: 2

Related Questions