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

Feedback

Input format: The editor controls below will assist with Markdown syntax.

Status

Sub-status

Your info

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.

Contact Matt

Similar Entries

Stats

2 unique visits since August 2008

Syndicate

Advertisements