- str_repeat: documentation ( source)
- preg_match_all: documentation ( source)
<?php
$i='4N4P9N7P1N1P2N2P';
preg_match_all('/(\d+)(\w)/', $i, $m);
//print_r($m);
foreach($m as $p) {
if ($p[2]=='N') {
$o.=str_repeat('=',$p[1]);
} else {
$o.=str_repeat('- ',(int)($p[1]/2)).($p%2?'-':'');
}
}
echo(PREG_SET_ORDER);
echo($o);