<?php
$re = '/(EC)\w{2}|(CC)\w{2}|\w(F)\w{2}|(LT)\w{2}|\w(T)\w{2}/';
$str = 'STAR';
preg_match($re, $str, $matches);
// Remove empty values and reset keys
$cat = array_values(array_filter($matches));
$categories = [
'CB' => 'Compact',
'CC' => 'Compact',
'CD' => 'Compact',
'EB' => 'Economy',
'EC' => 'Economy',
'ED' => 'Economy',
'IB' => 'Mid-Size',
'IC' => 'Mid-Size',
'ID' => 'Mid-Size',
'PB' => 'Premium',
'PC' => 'Premium',
'PD' => 'Premium',
'SB' => 'Standard',
'SC' => 'Standard',
'SD' => 'Standard',
'0L' => 'Luxury',
'F' => 'SUV',
'1G' => 'Crossover',
'1K' => 'Commercial',
'1P' => 'Pickup Truck',
'1Q' => 'Pickup Truck',
'1R' => 'RV',
'1S' => 'Sports',
'T' => 'Convertible',
'1V' => 'Van',
'1W' => 'Wagon',
'3H' => 'Hybrid',
'3I' => 'Hybrid',
'3C' => 'Electric',
'3E' => 'Electric',
];
//Echo category
Echo $categories[$cat[1]];
- Output for 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.29, 8.2.0 - 8.2.23, 8.3.0 - 8.3.11
- Convertible
preferences:
67.23 ms | 407 KiB | 5 Q