- str_repeat: documentation ( source)
- preg_match_all: documentation ( source)
<?php
$i='4N4P9N7P1N1P2N2P';
preg_match_all('/(\d+)(\w)/',$i,$m,2);
//foreach($m as $p){$k=$p[1];$o.=($p[2]=='N')?str_repeat('=',$k):str_repeat('- ',$k/2-$k%2).($k%2?'-':'');}
foreach($m as $p){$k=$p[1];
$o.=str_repeat($p[2]=='N'?'=':'-',$k);
}
$a=str_repeat('_',$n=strlen($o));
echo("$a\n\n\n$o\n\n$a\n");