<?php function previewTotalLength($labels){ $count = mb_strlen('rfc-vote ') - 2; foreach($labels as $label){ $countEllipsis = $label['trim'] ? 1 : 0; $count += $label['length'] - $label['trim'] + $countEllipsis + 2; } return $count; } function calcTrim($labels, $largestLabelLength, $chars, $stopAtTargetLength){ foreach($labels as $i => $label){ $labels[$i]['trim'] = max((int)floor(($label['length'] - 20) / $largestLabelLength * $chars), 0); if(previewTotalLength($labels) <= $stopAtTargetLength){ $chars++; } } return $labels; } $d = "Typed Properties,PHP Attributes,Functional Interfaces,Closure from callable function,Forbid dynamic calls to scope introspection functions,Callable prototypes"; $labelsList = []; foreach(explode(",", $d) as $label){ $labelsList[] = ['label' => $label, 'length' => mb_strlen($label), 'trim' => 0]; } $largestLabelLength = 0; foreach($labelsList as $label){ if($label['length'] > $largestLabelLength){ $largestLabelLength = $label['length']; } } $strip = 2; while(previewTotalLength($labelsList) > 150){ $labelsList = calcTrim($labelsList, $largestLabelLength, $strip++, 150); } print_r($labelsList); print_r(previewTotalLength($labelsList)); // preview result echo "\n"; echo "rfc-vote "; foreach($labelsList as $label){ $b = mb_substr($label['label'], 0, $label['length'] - $label['trim']); $b .= $label['trim'] ? '…' : ''; $collect[] = $b; } echo implode(', ', $collect);
You have javascript disabled. You will not be able to edit any code.
Value for `_results` contains invalid data `array`