从字符串中删除英镑符号 [英] Stripping the Pound sign from a string
问题描述
大家好,
我的HTML文档中有一个表单,要求用户输入商品的PRICE,并且该表单由PHP发布.
要发布的字符串的格式为:0.00英镑,或00.00英镑,000.00英镑等.
基本上,我试图剥离英镑符号,但保留小数点,这样它就可以进入我的sql数据库中.
有没有解决此问题的简单方法?我尝试使用 mysql_real_escape_string 和 str_replace ,但是它不适合我!
任何评论和答案都将不胜感激.
汤姆,敬上.
如果字符串具有 始终 格式,然后看看这个:
http://php.net/manual/en/function.substr.php [ ^ ]
通过这种操作,您可以始终删除任何字符串中的第一个字符...
如果字符串 t始终不具有 格式,请查看以下内容:
如果 http://php.net/manual/en/function.str-replace.php [ ^ ]不适用于您. ..
然后,您可以查看正则表达式:
http://php.net/manual/en/function.preg-match.php [ ^ ]
http://weblogtoolscollection.com/regex/regex.php [
string = ' \
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.
If the string has always that format, then take a look at this:
http://php.net/manual/en/function.substr.php[^]
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 http://php.net/manual/en/function.str-replace.php[^] is not working for you...
Then you could look at regular expressions:
http://php.net/manual/en/function.preg-match.php[^]
http://weblogtoolscollection.com/regex/regex.php[^]
hope this helps...
Adding with Joan, You can extract the number part only from your string.
string='\
这篇关于从字符串中删除英镑符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!