3v4l.org

run code in 300+ PHP versions simultaneously
<?php //+ Jonas Raoni Soares Silva //@ http://jsfromhell.com function AbstractHTMLContents($html, $maxLength=100){ mb_internal_encoding("UTF-8"); $printedLength = 0; $position = 0; $tags = array(); $newContent = ''; $html = $content = preg_replace("/<img[^>]+\>/i", "", $html); while ($printedLength < $maxLength && preg_match('{</?([a-z]+)[^>]*>|&#?[a-zA-Z0-9]+;}', $html, $match, PREG_OFFSET_CAPTURE, $position)) { list($tag, $tagPosition) = $match[0]; // Print text leading up to the tag. $str = mb_strcut($html, $position, $tagPosition - $position); if ($printedLength + mb_strlen($str) > $maxLength){ $newstr = mb_strcut($str, 0, $maxLength - $printedLength); $newstr = preg_replace('~\s+\S+$~', '', $newstr); $newContent .= $newstr; $printedLength = $maxLength; break; } $newContent .= $str; $printedLength += mb_strlen($str); if ($tag[0] == '&') { // Handle the entity. $newContent .= $tag; $printedLength++; } else { // Handle the tag. $tagName = $match[1][0]; if ($tag[1] == '/') { // This is a closing tag. $openingTag = array_pop($tags); assert($openingTag == $tagName); // check that tags are properly nested. $newContent .= $tag; } else if ($tag[mb_strlen($tag) - 2] == '/'){ // Self-closing tag. $newContent .= $tag; } else { // Opening tag. $newContent .= $tag; $tags[] = $tagName; } } // Continue after the tag. $position = $tagPosition + mb_strlen($tag); } // Print any remaining text. if ($printedLength < $maxLength && $position < mb_strlen($html)) { $newstr = mb_strcut($html, $position, $maxLength - $printedLength); $newstr = preg_replace('~\s+\S+$~', '', $newstr); $newContent .= $newstr; } // Close any open tags. while (!empty($tags)) { $newContent .= sprintf('</%s>', array_pop($tags)); } return $newContent; } $sText = '<p>Ключевым элементом в области снижения влияния объектов производства на водные ресурсы является уменьшение забора воды и качество <i>очистительных</i> процедур.</p> <p>Для <strong>этих</strong> целей Группа «Газпром» проводит организационно-технические мероприятия, <img src="http://osb.loc/images/logo.jpg" alt="test" text> в частности по установке средств измерения расхода воды, а также установке и наладке запорно-затворной арматуры на своих предприятиях, что способствует существенной экономии водных ресурсов.</p> <p>Повышение эффективности действующих очистных сооружений и внедрение новых технологий очистки стоков позволяет обеспечить нормативное качество очистки сточных вод. Общая мощность очистных сооружений «Газпрома» в 2010 г. составила 153,263 млн куб. м. Половина нормативно очищенных стоков прошла очистку на сооружениях биологической очистки, 39% — механической очистки, 12% — физико-химической очистки сточных вод.</p>'; //echo String::truncate( $sText, 150, ' ...'); //jo<... //echo "\n\n\n"; echo AbstractHTMLContents( $sText, 30, ' ...', true); //jo<i><b>n</b></i>... //echo "\n\n\n"; //echo String::truncate( $sText, 150, ' ...', false); //jo<i><b>n...
Output for 4.3.3 - 4.3.11, 4.4.0 - 4.4.9, 5.0.0 - 5.0.5, 5.1.1 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 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.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
<p>Ключевым</p>
Output for 5.1.0
Fatal error: fatal flex scanner internal error--end of buffer missed in /in/s4Ick on line 79
Process exited with code 255.
Output for 4.3.0 - 4.3.2
Warning: Wrong parameter count for preg_match() in /in/s4Ick on line 14 <p>Ключевым

preferences:
285.03 ms | 401 KiB | 456 Q