3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $string = 'Hello {{ name }}, nice to meet you.'; define('TAG_OPEN', '{{'); define('TAG_CLOSE', '}}'); define('STATE_TEXT', 'STATE_TEXT'); define('STATE_IN_TAG', 'STATE_IN_TAG'); function isOpenTag($string, $index) { return TAG_OPEN === substr($string, $index, strlen(TAG_OPEN)); } function isCloseTag($string, $index) { return TAG_CLOSE === substr($string, $index, strlen(TAG_CLOSE)); } function isText($string, $index) { return ! (isOpenTag($string, $index) || isCloseTag($string, $index)); } $state = STATE_TEXT; for($index = 0; $index < strlen($string); $index++) { if (isText($string, $index) && $state != STATE_IN_TAG) { continue; } if (isOpenTag($string, $index)) { $state = STATE_IN_TAG; $index += strlen(TAG_OPEN); continue; } if (isText($string, $index) && $state = STATE_IN_TAG) { echo $index, ' ', $string[$index], PHP_EOL; } if (isCloseTag($string, $index)) { $state = STATE_TEXT; $index += strlen(TAG_CLOSE); continue; } }
Output for 4.3.10 - 4.4.9, 5.0.2 - 5.6.21, hhvm-3.12.0, 7.0.0 - 7.1.0
9 n 10 a 11 m 12 e 13
Output for hhvm-3.10.0

Process exited with code 153.
Output for 4.3.0 - 4.3.9, 5.0.0 - 5.0.1
9 n Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/3F6RG on line 36 PHP_EOL10 a Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/3F6RG on line 36 PHP_EOL11 m Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/3F6RG on line 36 PHP_EOL12 e Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/3F6RG on line 36 PHP_EOL13 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/3F6RG on line 36 PHP_EOL