Bilal Khalid
Bilal Khalid

Reputation: 95

Dealing with Whitespaces in url using PHP or codeigniter

I am working on a project that requires me to take post code from URL. Since the postcode has got space in it,I have two options to achieve this: 1) Either construct a URL with postcode having a space like this:

  http://myhostname/seven/locator/PC1%201LA

OR

2) Grab postcode from url and Insert whitespace in the decoded url:

 http://myhostname/seven/locator/PC11LA

But i am not sure how to do as my Post code could be like this: MM11 5PW instead PC1 1LA

How can i achieve and sort this problem ?How can i send whitespaces in the url so that it could give me post code like these: MM1 5PW or PC11 6MP????

NOTE :I am using QR code reader to naviagte to website.The + plus sign is not recognised by the QR reader.

Upvotes: 0

Views: 2025

Answers (2)

RWC
RWC

Reputation: 5052

Creating the url with the postcode:

<?php

$postCode = 'MM11 5PW';
$url = 'http://myhostname/seven/locator?postcode=' . urlencode($postCode );

?>

Somewhere in your locator controller...

<?php

$postCode = urldecode($_GET['postcode']);
echo 'Posted postcode: ' . $postCode;

?>

Upvotes: 1

Sven
Sven

Reputation: 70853

Percent-encoded spaces "%20" work well.

But I'd rather send them inside the query string: http://hostname/seven/locator?postcode=PC1%201LA

Upvotes: 0

Related Questions