3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function truncate($string, $chars = 100, $terminator = ' …') { var_dump($string, $chars, $terminator); var_dump(mb_strlen($terminator)); $cutPos = $chars - mb_strlen($terminator); var_dump($cutPos); var_dump(mb_strpos($string, ' ', $cutPos)); var_dump(mb_substr($string, 0, mb_strpos($string, ' ', $cutPos))); $boundaryPos = mb_strrpos(mb_substr($string, 0, mb_strpos($string, ' ', $cutPos)), ' '); var_dump($boundaryPos); var_dump(mb_substr($string, 0, $boundaryPos === false ? $cutPos : $boundaryPos) . $terminator); return mb_substr($string, 0, $boundaryPos === false ? $cutPos : $boundaryPos) . $terminator; } echo truncate("#mercedes#benz#flow#summer#drunk#guys#abiball#effzeh#köln#aha#böttiman#mied#labums");
Output for 5.6.7 - 5.6.28, 7.0.0 - 7.1.0
string(88) "#mercedes#benz#flow#summer#drunk#guys#abiball#effzeh#köln#aha#böttiman#mied#labums" int(100) string(4) " …" int(2) int(98) Warning: mb_strpos(): Offset not contained in string in /in/H1Xso on line 7 bool(false) Warning: mb_strpos(): Offset not contained in string in /in/H1Xso on line 8 string(0) "" Warning: mb_strpos(): Offset not contained in string in /in/H1Xso on line 9 bool(false) string(92) "#mercedes#benz#flow#summer#drunk#guys#abiball#effzeh#köln#aha#böttiman#mied#labums …" #mercedes#benz#flow#summer#drunk#guys#abiball#effzeh#köln#aha#böttiman#mied#labums …
Output for hhvm-3.10.0 - 3.12.0
string(88) "#mercedes#benz#flow#summer#drunk#guys#abiball#effzeh#köln#aha#böttiman#mied#labums" int(100) string(4) " …" int(2) int(98) Warning: Offset not contained in string. in /in/H1Xso on line 7 bool(false) Warning: Offset not contained in string. in /in/H1Xso on line 8 string(0) "" Warning: Offset not contained in string. in /in/H1Xso on line 9 bool(false) string(92) "#mercedes#benz#flow#summer#drunk#guys#abiball#effzeh#köln#aha#böttiman#mied#labums …" #mercedes#benz#flow#summer#drunk#guys#abiball#effzeh#köln#aha#böttiman#mied#labums …
Output for 5.2.9 - 5.5.35
string(88) "#mercedes#benz#flow#summer#drunk#guys#abiball#effzeh#köln#aha#böttiman#mied#labums" int(100) string(4) " …" int(4) int(96) Warning: mb_strpos(): Offset not contained in string in /in/H1Xso on line 7 bool(false) Warning: mb_strpos(): Offset not contained in string in /in/H1Xso on line 8 string(0) "" Warning: mb_strpos(): Offset not contained in string in /in/H1Xso on line 9 bool(false) string(92) "#mercedes#benz#flow#summer#drunk#guys#abiball#effzeh#köln#aha#böttiman#mied#labums …" #mercedes#benz#flow#summer#drunk#guys#abiball#effzeh#köln#aha#böttiman#mied#labums …
Output for 4.4.5 - 4.4.9, 5.2.1 - 5.2.8
string(88) "#mercedes#benz#flow#summer#drunk#guys#abiball#effzeh#köln#aha#böttiman#mied#labums" int(100) string(4) " …" int(4) int(96) Warning: mb_strpos(): Offset not contained in string. in /in/H1Xso on line 7 bool(false) Warning: mb_strpos(): Offset not contained in string. in /in/H1Xso on line 8 string(0) "" Warning: mb_strpos(): Offset not contained in string. in /in/H1Xso on line 9 bool(false) string(92) "#mercedes#benz#flow#summer#drunk#guys#abiball#effzeh#köln#aha#böttiman#mied#labums …" #mercedes#benz#flow#summer#drunk#guys#abiball#effzeh#köln#aha#böttiman#mied#labums …
Output for 4.3.2 - 4.4.4, 5.0.0 - 5.2.0
string(88) "#mercedes#benz#flow#summer#drunk#guys#abiball#effzeh#köln#aha#böttiman#mied#labums" int(100) string(4) " …" int(4) int(96) Warning: mb_strpos(): Offset is out of range in /in/H1Xso on line 7 bool(false) Warning: mb_strpos(): Offset is out of range in /in/H1Xso on line 8 string(0) "" Warning: mb_strpos(): Offset is out of range in /in/H1Xso on line 9 Warning: mb_strrpos(): Empty haystack in /in/H1Xso on line 9 bool(false) string(92) "#mercedes#benz#flow#summer#drunk#guys#abiball#effzeh#köln#aha#böttiman#mied#labums …" #mercedes#benz#flow#summer#drunk#guys#abiball#effzeh#köln#aha#böttiman#mied#labums …
Output for 4.3.0 - 4.3.1
string(88) "#mercedes#benz#flow#summer#drunk#guys#abiball#effzeh#köln#aha#böttiman#mied#labums" int(100) string(4) " …" int(4) int(96) Warning: mb_strpos() [http://www.php.net/function.mb-strpos]: Offset is out of range in /in/H1Xso on line 7 bool(false) Warning: mb_strpos() [http://www.php.net/function.mb-strpos]: Offset is out of range in /in/H1Xso on line 8 string(0) "" Warning: mb_strpos() [http://www.php.net/function.mb-strpos]: Offset is out of range in /in/H1Xso on line 9 Warning: mb_strrpos() [http://www.php.net/function.mb-strrpos]: Empty haystack in /in/H1Xso on line 9 bool(false) string(92) "#mercedes#benz#flow#summer#drunk#guys#abiball#effzeh#köln#aha#böttiman#mied#labums …" #mercedes#benz#flow#summer#drunk#guys#abiball#effzeh#köln#aha#böttiman#mied#labums …