3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $string = 'Samsung UN32EH4003 32-inch 720p 60Hz LED HDTV (Black)'; echo shorten_string($string); function shorten_string($string,$count=5){ $arr = preg_split('/[,\ \.;]/', $string); $keywords = array_unique($arr); $i=0; $rtn = ''; foreach ($keywords as $keyword){ if ((preg_match("/^[a-z0-9]/", $keyword) ) && (strlen($keyword) > 3)){ $rtn .= $keyword.' '; $i++; if ($i==$count) break; } } return trim($rtn); }
Output for 4.3.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
32-inch 720p 60Hz