Click here to Skip to main content
12,697,178 members (23,783 online)
Rate this:
Please Sign up or sign in to vote.
See more: HTML PHP
Hi everyone,

I have a form on my HTML document that requires the user to type in a PRICE for an item, and it is POSTED by PHP.

The format of the string that is being posted is: £0.00, or £00.00, £000.00 etc.

Basically I'm trying to strip away the Pound Sign but keep the decimal place, so that it goes in my sql database OK.

Is there an easy way around this? I tried using mysql_real_escape_string and str_replace but it doesnt want to work for me!!

Any comments and answers are greatly appreciated.

Regards, Tom.
Posted 3-Sep-12 5:50am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

If the string has always that format, then take a look at this:[^]

With this kind of operation you could remove the first char always in any string...

If the string doesn't has always that format, then take a look at this:

If[^] is not working for you...

Then you could look at regular expressions:[^][^]

hope this helps...
thomasriley 3-Sep-12 11:14am
Hi Joan, if the string is not always in that format, do you have any suggestions? For example, if I could search for the Pound Sign first, and if it exists, get rid of it, if it doesn't exist, then save the string how it is?
Joan Murt 3-Sep-12 11:20am
Sorry badly explained, the first is only the one that's affected by the format, the others are precisely independent on the format... Take a look at them I'm sure that one or another will work for you.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Adding with Joan, You can extract the number part only from your string.

 if(is_numeric($string[$i])==true || $string[$i]=='.' || || $string[$i]=='-')

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.170118.1 | Last Updated 4 Sep 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100