I wrote this PHP code to make some substitutions:
function cambio($txt){
$from=array(
'/\+\>([^\+\>]+)\<\+/', //finds +>text<+
'/\%([^\%]+)\%/', //finds %text%
);
$to=array(
'<span class="P">\1</span>',
'<span>\1</span>',
);
return preg_replace($from,$to,$txt);
}
echo cambio('The fruit I most like is: +> %apple% %banna% %orange% <+.');
Resulting into this:
The fruit I most like is: <span class="P"> <span>apple</span> <span>banna</span> <span>orange</span> </span>.
However I needed to identify the fruit's span tags, like this:
The fruit I most like is: <span class="P"> <span class="t1">apple</span> <span class="t2">banana</span> <span class="t3">coco</span> </span>.
I'd buy a fruit to whom discover a regular expression to accomplish this :-)
Whit the Xavier Barbosa's help, I came to this final sollution:
function matches($matches){
static $pos=0;
return sprintf('<span class="t%d">%s</span>',++$pos,$matches[1]);
}
function cambio($txt){//Markdown da Atípico : Deve ser usado depois do texto convertido para markdown
$from=array(
'/\=>(.+?)<\=/', //finds: =>text<=
'/\+>(.+?)<\+/', //finds +>text<+
);
$to=array(
'<span class="T">\1</span>',
'<span class="P">\1</span>',
);
$r=preg_replace($from,$to,$txt);
return preg_replace_callback('/%(.*?)%/','matches',$r);//finds %text%
//'/%((\w)\w+)%/' //option
}