I assumed there’d be an easy way in PHP to convert a string like 18 5/16 into the float 18.3125. I can’t find a straightforward function to do it. Is there one, or do I need to write my own?
I assumed there’d be an easy way in PHP to convert a string like
Share
I don’t think such a function exists — at least not bundled with PHP.
Writing a function that does this operation, if your string always have the same format, should not be too hard ; for example, I’d say that something like this should do the trick :
Which will get you the following output :
And you might get something shorter with a few regex ; something like this should do the trick, I suppose :
Else, not bundled in PHP, but already existing, maybe this class could help : Eval Math.
Disclaimer : I have not tested it — so not quite sure it’ll work in your specific situation.