0

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.

4
  • Use + sign instead of %20. Commented Jan 30, 2013 at 9:10
  • @tereško.I am using QR code reader to naviagte to website.The + plus sign is not recognised by the reader.Any other idea? Commented Jan 30, 2013 at 9:16
  • Each country has different post code format (for exampl, Latvia has LV-0000 format) , which means that, if you cannot use + signs, then you will have to use %20. There is no way around it. Commented Jan 30, 2013 at 9:25
  • 1
    use php's urlencode and urldecode Commented Jan 30, 2013 at 10:10

2 Answers 2

1

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;

?>
Sign up to request clarification or add additional context in comments.

Comments

0

Percent-encoded spaces "%20" work well.

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

2 Comments

Send them as query string? Why?
But I am using QR code reader to navigate to website.The + or other symbols are not recognised by the reader.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.