Passing decimals in the URL Feb09 '06
Passing variables in the URL is "commonplace" when developing web applications.
When the variable is a simple word or number - it’s usually no problem:
http://mysite.com/index.php?accountid=634&accountname=Wilkinson
However, many times you’ll need to use certain characters, such as a space, period, or quote - in the URL, and many characters simply aren’t allowed.
For example, try passing a dollar amount:
http://mysite.com/index.php?revenue=4600.00
Notice that extra period (.) in the URL. That obviously can’t be there.
The browser will naturally escape such characters, but how do you put them back, on the other end? (at the page that processes the URL variable)
The period, in this case, is converted to this character:
%2e
(You can see a much more robust list of such conversions at W3Schools.)
So, on the other end, simply "find and replace" the period, when passing a decimal value across pages.
PHP:
str_replace( "%2e", ".", $decimal_value );
ASP:
replace( decimal_value, "%2e", "." )
In both cases, we simply search for "%2e" - and then replace that with a period (.).
Categories: ASP
, PHP
, Programming ![]()
Add Feedback (view all)
Leave feedback
matthom
is published and produced by Matt Thommes - an independent publishing enthusiast, mobile blogger, content creator, informative writer, web developer from Chicago.
Never one to conform, Matt intends to promote the effect the web has on our lives, in an effort to intensify, instruct, and clarify all that is happening around us.
Similar Entries
- Accessible URL’s make life easier (59 recent visits)
- PHP: Skipping index page call in URL (171 recent visits)
- W3C on relative URL references in feeds (3 recent visits)
- Friendly URL’s at Amazon (3 recent visits)
- Flickr friendly URL’s (69 recent visits)
- mod_rewrite URL conversion (7 recent visits)
Stats
2 unique visits since August 2008