Skip to content

Instantly share code, notes, and snippets.

@gingerbeardman
Last active August 29, 2015 14:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gingerbeardman/cc7e64032e1c0c295bef to your computer and use it in GitHub Desktop.
Save gingerbeardman/cc7e64032e1c0c295bef to your computer and use it in GitHub Desktop.
<?php
echo "<pre>";
$subject = "This is a test {pause}3{/pause} for embedded tags. {shake}1.5{/shake} Tada! {wait}keySpace{/wait}\n";
$pattern = "#{([\w]+)}(.*?){/\\1}\s#";
preg_match_all($pattern, $subject, $matches);
$split = preg_split($pattern, $subject);
print_r($subject);
echo "\n";
print_r($split);
print_r($matches);
echo "\n";
$cmd = 0;
//for each split string
foreach($split as $m) {
$chars = str_split($m);
//for each character
foreach($chars as $c) {
//output it
echo "$c";
}
//fire tag command
if ($cmd < count($matches[1])) echo "\ncmd:". $matches[1][$cmd] ."(". $matches[2][$cmd] .")\n";
$cmd++;
}
echo "</pre>";
?>
This is a test {pause}3{/pause} for embedded tags. {shake}1.5{/shake} Tada! {wait}keySpace{/wait}
Array
(
[0] => This is a test
[1] => for embedded tags.
[2] => Tada!
[3] =>
)
Array
(
[0] => Array
(
[0] => {pause}3{/pause}
[1] => {shake}1.5{/shake}
[2] => {wait}keySpace{/wait}
)
[1] => Array
(
[0] => pause
[1] => shake
[2] => wait
)
[2] => Array
(
[0] => 3
[1] => 1.5
[2] => keySpace
)
)
This is a test
cmd:pause(3)
for embedded tags.
cmd:shake(1.5)
Tada!
cmd:wait(keySpace)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment