How to convert imperial units of length into metric?

前端 未结 5 1747
心在旅途
心在旅途 2021-01-14 07:16

Here I am faced with an issue that I believe(or at least hope) was solved 1 million times already. What I got as the input is a string that represents a length of an object

5条回答
  •  独厮守ぢ
    2021-01-14 07:59

    The regexp would look something like this:

    "([0-9]+)'\s*([0-9]+)\""
    

    (where \s represents whitespace - I'm not sure how it works in php). Then you extract the first + second group and do

    (int(grp1)*12+int(grp2))*2.54
    

    to convert to centimeters.

提交回复
热议问题