FutonGuy Posted April 20, 2010 Share Posted April 20, 2010 Hi, I am trying to extract numbers out from a field which is in alphanumeric. Did a search on the web and found that i can actually use "number_format" to extract the numbers out from the field. However i receive some notices and warning which read: 1) Notice: A non well formed numeric value encountered in C:\db\update.php on line 50 2) Warning: number_format() expects parameter 1 to be double, string given in C:\db\date.php on line 50 my code is : $HW_dev = $row_export['HW_dev_num' $HW_dev_num = number_format($HW_dev,0,'',''); Can someone able to assist on this issue? thank you and your help is greatly appreciated. Cheers Quote Link to comment Share on other sites More sharing options...
salathe Posted April 20, 2010 Share Posted April 20, 2010 Your PHP code snippet contains invalid syntax, I'm going to assume that does not occur in your actual code (since a different error would be issued). Can you give an (or some) example of the values for $HW_dev as that would help us to diagnose why they cannot be formatted as a number. Quote Link to comment Share on other sites More sharing options...
FutonGuy Posted April 20, 2010 Author Share Posted April 20, 2010 Hi, HW_Dev is a value that might look like this : BNM1234CO I want to extract just the number, 1234, out from this HW_Dev. thanks Quote Link to comment Share on other sites More sharing options...
salathe Posted April 20, 2010 Share Posted April 20, 2010 Ahh now that makes sense, you can't just ask PHP to magically figure out where the number is in there: you need to extract it yourself. Depending on the format of the "number", various solutions might be more useful. For example you could simply get rid of all non-dijit characters in the string, or look for only the first sequence of digits, or extract a specific sub-string if they're always at the same position and length, or do something else entire if none of those are suitable to your specific needs. Quote Link to comment Share on other sites More sharing options...
FutonGuy Posted April 21, 2010 Author Share Posted April 21, 2010 Will you be able to show me some examples how should i do it? Thanks Quote Link to comment Share on other sites More sharing options...
salathe Posted April 21, 2010 Share Posted April 21, 2010 Will you be able to show me some examples how should i do it? Only for the specific value that you've provided, anything other than that would be guesswork. $value = 'BNM1234CO'; $number = strspn($value, '1234567890'); echo $number; In this case the call to number_format is not needed because you were asking for the number to be formatted with no decimal places, no thousands separator and no decimal separator.... in other words, it will not make a difference. Also note that the above is one of many (many!) ways to get a number from a string and could well turn out to be useless for your needs but that's all I/we can do with people who don't answer questions designed to help yourself. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.