0

I am having a string United States and i need to use this like United%20States. For this i am using urlencode("United States"); But, it is giving me the result as United+States. Please help me in getting me my output as United%20States

Thanks!

  • Not answering your question, but I'd suggest avoiding the %20 and using "-" instead. Especially if this is part of an url, people have a much easier time reading - than %20 – Noam Oct 31 '13 at 08:48

6 Answers6

2

You can use rawurlencode in this case (http://php.net/manual/en/function.rawurlencode.php)

Clart Tent
  • 1,319
  • 2
  • 9
  • 11
1

You want rawurlencode, which

Encodes the given string according to » RFC 3986.

Note that urlencode says:

This differs from the » RFC 3986 encoding (see rawurlencode()) in that for historical reasons, spaces are encoded as plus (+) signs.

See also:

Community
  • 1
  • 1
Jonathon Reinhart
  • 132,704
  • 33
  • 254
  • 328
0

You can use rawurlencode to achieve it- http://php.net/manual/en/function.rawurlencode.php

Ramesh
  • 4,223
  • 2
  • 16
  • 24
0

Try using rawurlencode Refer: http://us2.php.net/manual/en/function.rawurlencode.php

mintuhouse
  • 449
  • 5
  • 16
0

Use this instead

<?php echo rawurlencode("United States"); ?>
Krishnadas PC
  • 5,981
  • 2
  • 53
  • 54
0

<?php // str_rot13() example $string = 'Encoding and Decoding Encrypted PHP Code'; $encoded = str_rot13($string); $decoded = str_rot13(str_rot13($string)); echo $encoded ."\n"; echo $decoded; ?>

kkp
  • 1
  • 1