php - Find coresponding open/close brackets -


a follow on previous question: php how best edit rtf file

i believe have solution, need more help. found if use merge fields in template builder, php code find/replace fields in pattern: "{\field}" problem is, though, need find whole string, remove rtf tags, , compare text left behind. first step, though, find full markup. , stuck. need able find entire string length, open "{" close "}", possible other sets of "{}" in between. example:

{\field{\*\fldinst {\rtlch\fcs1 \af31507 \ltrch\fcs0 \insrsid11370280  mergefield details_awardee_name }}{\fldrslt {\rtlch\fcs1 \af31507 \ltrch\fcs0  \lang1024\langfe1024\noproof\insrsid11370280 \'abdetails_awardee_name\'bb}}} 

as can see, example has multiple embedded markup sets. string within pages of more markup. know way entire string length? can done regex? once accomplished, can move on stripping tags , comparing.

thanks jason

you can use recursive pattern available option pcre_extended (x). here comes example:

$str = 'test { enclosed { sub   }} end'; $p = '~\{ ( (?>[^{}]+) | (?r) )* \}~x';  preg_match_all($p, $str, $m); var_dump($m); 

output:

array(2) {   [0] =>   array(1) {     [0] =>     string(21) "{ enclosed { sub   }}"   }   [1] =>   array(1) {     [0] =>     string(9) "{ sub   }"   } } 

Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -