3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function stripLocationName($name, $length = 30) { if(strlen($name) > $length) { $iata = false; if(preg_match("/ \[[A-Z]{3}\]/", $name, $iata)) { $name = substr($name, 0, -6); $iata = $iata[0]; } $name = substr($name, 0, $length - ($iata ? strlen($iata)+3 : 0)) . ($iata ? '...' . strtoupper($iata) : ''); } return $name; } $name = 'Sumburgh - Shetlandsöarna Flygplats [LSI]'; echo strlen($name) . '<br>'; $name = stripLocationName($name); echo $name; echo ' . ' . strlen($name);
Output for 4.3.0 - 7.1.0
44<br>Sumburgh - Shetlands�... [LSI] . 30