@ 2014-07-01T09:28:17Z <?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;
}
}
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Output for 4.3.10 - 4.3.11 , 4.4.0 - 4.4.9 , 5.0.2 - 5.0.5 , 5.1.0 - 5.1.6 , 5.2.0 - 5.2.17 , 5.3.0 - 5.3.29 , 5.4.0 - 5.4.45 , 5.5.24 - 5.5.35 , 5.6.7 - 5.6.21 , 7.0.0 - 7.0.20 , 7.1.0 - 7.1.10 , 7.2.0 - 7.2.33 , 7.3.12 - 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 9 n
10 a
11 m
12 e
13
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 preferences:dark mode live preview
200 ms | 402 KiB | 312 Q