This small application was prompted by the following post https://phpc.social/@nando161@partyon.xyz/117123893682362282
Converting shoes size is difficult, too difficult!!
I discovered schuhgroessen-umrechner and, inspired by Sarah's excellent work, built this small library as an independent reimplementation.
- PHP >= 8.4 is required but the latest stable version of PHP is recommended.
Important
If the conversion data is stored in a CSV file you will have to install league/csv >= 9.28
If the conversion data is stored in a database, ext-pdo support is required.
Shoe size converter is available on Packagist and can be installed using Composer:
composer require bakame/shoe-size-converter
The original script by Sarah Amft has been reimplemented using this library's API
and is available in the public directory. It provides a small single-page application
for converting adult and children's shoe sizes between supported shoe size systems.
To run the converter locally:
- Install this repo via git clone,
- Run
composer install - Change to the
publicdirectory inside the root directory, - Start PHP's built-in development server:
php -S localhost:4000Then open http://localhost:4000/ in your browser.
The application allows you to convert both adult and children's shoe sizes.
The package also provides a command-line converter.
To run the CLI command locally:
- Install this repo via composer
vendor/bin/shoe-converter EU 42.5This returns:
Shoe size conversion
Input
eu 42.5 (adults)
Sizes (calculated)
mondopoint 270
cm 27
eu 42.5
uk 9
us_men 10
us_women 11
Measurements
27 cm
10.629921259843 inThe first argument is the input shoe size unit, followed by the shoe size value. For example:
vendor/bin/shoe-converter EU 42.5
vendor/bin/shoe-converter UK 9
vendor/bin/shoe-converter US_MEN 10You can specify the shoe size system using the --type or -t option. The
supported values are adults and children. The adults system is used by
default when no type is explicitly specified.
vendor/bin/shoe-converter EU 7.5 --type children
vendor/bin/shoe-converter UK 9 -t children
vendor/bin/shoe-converter US_MEN 10 --type adults| Option | Description | Default |
|---|---|---|
--type, -t |
Shoe size system: adults or children |
adults |
Create a shoe size using one of the supported units:
use Bakame\Shoes\AdultUnit;
use Bakame\Shoes\ChildUnit;
$euShoeSize = AdultUnit::Eu->of(43);
// $euShoeSize is an instance of Bakame\Shoes\AdultSize
$ukChildSize = ChildUnit::Uk->of(7.5);
// $ukChildSize is an instance of Bakame\Shoes\ChildSizeBoth instances expose their numeric value and unit:
$euShoeSize->size;
// 43
$euShoeSize->unit;
// AdultUnit::Eu
$euShoeSize->label();
// EU 43Important
Adult and children's shoe sizes differ in how their conversions are determined. Adult shoe sizes can be converted using deterministic foot-length-based formulas, whereas children's shoe sizes MUST use a specific conversion table.
AdultSize supports deterministic shoe-size calculations based on foot length.
You can calculate an equivalent shoe size in any supported adult unit using
AdultSize::in():
$ukShoeSize = $euShoeSize->in(AdultUnit::Uk);
// returns an AdultSize containing the calculated UK size
$ukShoeSize->size;
// 9.5
$ukShoeSize->unit;
// AdultUnit::UkThe calculated value is the nearest size supported by the target sizing system. It is not a lookup in the ISO conversion table.
You can also calculate all supported adult equivalents at once with
AdultSize::equivalents():
$result = $euShoeSize->equivalents();
// returns an array containing the calculated equivalent shoe sizes
// for all supported adult unitsThese calculation methods are only available for AdultSize. Children's shoe
sizes cannot be calculated using foot-length-based formulas and therefore must
be converted using the conversion table.
An AdultSize can also be represented by its physical foot measurement via its
dedicated $footLength property, expressed as a Bakame\Shoes\Length.
The Length class allows converting the length to millimeters, centimeters,
or inches:
use Bakame\Shoes\Length;
use Bakame\Shoes\LengthUnit;
$footLength = $ukShoeSize->footLength;
// returns a Bakame\Shoes\Length instance
$footLength->in(LengthUnit::Millimeter);
// returns the length in millimeters 275
$footLength->in(LengthUnit::Centimeter);
// returns the length in centimeters 27.5
$footLength->in(LengthUnit::Inch);
// returns the length in inches 10.826771653543These measurements are calculated from the shoe size's foot length and are independent of the conversion lookup table.
Adult shoe sizes can be compared by their physical foot length using
Length::compare(). This compares the underlying measurement, regardless of
the shoe-size system or length unit:
use Bakame\Shoes\Length;
Length::compare($ukShoeSize, $euShoeSize);
// returns -1, 0, or 1The comparison returns a negative value when the first shoe is shorter, 0
when both shoes have the same foot length, and a positive value when the first
shoe is longer.
For children's shoe sizes, where a foot-length calculation cannot be used,
Converter::footLength() retrieves the corresponding measurement from the
conversion table:
$footLength = $converter->footLength($ukChildSize);
$footLength->in(LengthUnit::Centimeter);
// returns the length found in the conversion table
// converted to centimetersConverter can also be used for adult shoe sizes. When an adult size or
measurement is not available in the conversion table, Converter falls back
to the corresponding calculation.
This means that Converter::size() and Converter::footLength() can be used
with both adult and children's shoe sizes while preserving the appropriate
conversion strategy for each system.
If you want to use the provided conversion data, use Converter.
Converter::size() and Converter::equivalents() use the configured conversion
table and fall back to the calculation algorithm when converting an AdultSize
if the required data is not available. For ChildSize, the conversion table is
the only source of conversion data.
These methods can be used for both adult and children's shoe sizes, provided
that the Converter is configured with the corresponding ShoeType.
For example:
$ukShoeSize = $converter->size($euShoeSize, AdultUnit::Uk);
// returns the UK equivalent found in the conversion tableOr retrieve all available equivalents:
$result = $converter->equivalents($euShoeSize);
// returns the equivalent shoe sizes found in the conversion tableIf no equivalent is present in the conversion table, Converter falls back to
the calculation algorithm for AdultSize. For ChildSize, no equivalent can
be calculated, so null is returned when no matching entry is found.
| Adult | Children | |
|---|---|---|
AdultSize::footLength |
Calculation | Not available |
AdultSize::in() |
Calculation | Not available |
AdultSize::equivalents() |
Calculation | Not available |
Converter::footLength() |
Table, then calculation | Table only |
Converter::size() |
Table, then calculation | Table only |
Converter::equivalents() |
Table, then calculation | Table only |
The converter can be created using one of the following data sources:
- a CSV file path or file stream;
- a PDO connection; or
- no data source, in which case the default conversion table is used.
When a file path or stream is provided, it must reference a valid CSV file with
the expected structure for the selected ShoeType. When a PDO connection is
provided, the database must contain the appropriate conversion table with the
expected columns for the selected ShoeType.
The expected structure depends on the shoe size system:
- Adults —
eu,us_men,us_women,uk,cm, andmondopoint. - Children —
eu,us,uk,cm, andmondopoint.
For CSV sources, these names must be provided as the column headers in the first row. For PDO sources, the data must be stored in the corresponding table:
shoe_sizes_adultsforShoeType::Adults.shoe_sizes_childrenforShoeType::Children.
Both tables must use the expected columns for their respective shoe size system.
This library is an independent reimplementation inspired by schuhgroessen-umrechner by Sarah Amft.
The original project provided the reference for the shoe-size conversion functionality. The implementation, API, and examples have been completely rewritten as a standalone library.
All credit for the original work and inspiration goes to Sarah Amft.
Contributions are welcome and will be fully credited. Please see CONTRIBUTING and CONDUCT for details.
If you discover any security related issues, please email nyamsprod@gmail.com instead of using the issue tracker.
Please see CHANGELOG for more information on what has changed recently.
The MIT License (MIT). Please see LICENSE for more information.
Happy Coding!

