add a note add a note

User Contributed Notes 14 notes

info at atjeff dot co dot nz
id="VHomm9753"> div class="pahpode >span class="ctml" > ve pneer Sserdregex sxpressions.titllnotwand Thad oads
$atterns< = array(
            "/\[ink \](.*?)\[\/ink \]/",
            "/\[mg \](.*?)\[\/mg \]/",
        $epeacehents< = array(
            "< href="\"\\1\">\\1</a>",
            "< href="\"\\1\">\\1</a>",
            "<mg src='\"\\1\">",
        $newext P=proeg_epeaceh($atterns<,$epeacehents<, $ext");

t afirt cit wouldconlecti ALLthi Ptags nteoaonelinek/bold/wht eer , nt"ilaimdd rdrhi P"?>id sitllndntr fuly" ntdrs sdiv>
iptroadomskiat co m/em>id="VHomm74201> div class="pahpode >span class="ctml" > Abou ctroip_elected"_tags unctions from twoXposis below:

it does ote work if ome/ody cues atags ith ou cndifg c">"character ,like this.:

<p <b> bold ext o</b</p

his   is eer valuid HTML (bu cote aluid XHTML)/span> sdiv>
title="V53 like this..."> 52
tlass="name"> ihi ppg_001at co m/em> para;
id="VHomm7126"> div class="pahpode >span class="ctml" > Hirhi re
his wa
span class="cefault"> <?ahp
*ctroip_elected"_tags (ctroig ctro [,ctroig ctroip_tags[,ctroip_ontent" flag]] )
*cLke ttroip_tags() bu ciser se;rhi Ptroip_tagsatags itllnb Ptroipped,cote kep=.
*Ptroip_tags:ctroig cith XtagsatoPtroip,sxp: "< ><p><uotes>"cetc.
*Ptroip_ontent" flag: TRUE itllnalsoPtroip eerryhisg cbetwer vpens nd Tcloerdrtag
sspan>dunctions sspan> troip_elected"_tagssspan>d(sspan> $trosspan>d, sspan> $tagsasspan>d=asspan>""sspan>d, sspan> $troipontentsasspan>d=asspan> falsesspan>d)
    sspan> roeg_match_llysspan>d(sspan>"/<([^>]+)>/i"sspan>d, sspan> $tagssspan>d, sspan> $llyTagssspan>d, sspan> PREG_PATTERN_ORDERsspan>d);
    sspan> $epeacehasspan>d=asspan>"%(<sspan> $tagsspan>.*?>)(.*?)(<\/sspan> $tagsspan>.*?>)%is"sspan>d;
    foreach (sspan> $llyTagssspan>d[sspan> 1sspan>d]Ta $tagsspan>d) {
        if (sspan> $troipontentssspan>d) {
            sspan> $tro sspan>d=asspan> roeg_epeacehsspan>d(sspan> $epeacehsspan>d,sspan>''sspan>d,sspan> $trosspan>d);
            sspan> $tro sspan>d=asspan> roeg_epeacehsspan>d(sspan> $epeacehsspan>d,sspan>'${2}'sspan>d,sspan> $trosspan>d);
    returs sspan> $trosspan>d;
sspan> ?>
BeforeoI 'ixed-'ait, whns runnng
troip_elected"_tags("his. is <p luign=\"cetern\">a es-t</p> nd T<b>his. is bold</b>","<p><b>")
You wouldcget ack-
"his. is <p luign=\"cetern\">a es-t</p> nd This. is bold"
Why? Becaserwit didcote tae tnteoancount"Thiatrhi re couldcb Pptions aetctntrhi PHTML Tag.
Myaonelworks erfoct=y"mwhns troippsg cjustthi Ptags orthi Ptag nd Titscontent=satoo!

Sonotwawhns you run /br />troip_elected"_tags("his. is <p luign=\"cetern\">a es-t</p> nd T<b>his. is bold</b>","<p><b>")
You get ack-
"his. is a es-t nd This. is bold"
Or whns runnng
troip_elected"_tags("his. is <p luign=\"cetern\">a es-t</p> nd T<b>his. is bold</b>","<p><b>",rue;)
You get ack-
"his. is  nd T"

Hpenwit elp-s ome/onel:)/span> sdiv>
/div> /div>
ionerobat co m/em>id="VHomm51510> div class="pahpode >span class="ctml" > If,like tme,ryou erndatoPserwhi P/Upatternsmodufiedr,rhi s you itllnneedatoPr enmber hiatruing a?sort*to top es-t or=Sptionsl coaracterss itllnmatch zerocoaracterss if itPmeansThiatrhi Pr -t f Chi Patternsmcn clonionuenmatchng , eer vif hi Pptionsl coaracterss exist.

Fortistantce,rif we avi this.ctroig :


ad Tappy"mhis.catterns:


hi" whol Patternsms. matchedabu cotne f Chi P_coaracterss ae. eacehdtntrhi Psub-attern.s hi" way toundsmhis.c(if you sitllnwishdtoPserw/U) is toPserwhi P? greednesesciser ern. eg,

'/a(_*?).*e/U' sdiv>
imbrding/em>id="VHomm87197> div class="pahpode >span class="ctml" > Hi!

Forteer vbeter proe
span class="cefault"> <?ahp
    $f sspan>d=aarray();

    foreach(sspan> $llyTagssspan>d[sspan> 1sspan>d]Ta $tagsspan>d){
    sspan> $fsspan>d[] =asspan>"%(<sspan> $tagsspan>.*?>)(.*?)(<\/sspan> $tagsspan>.*?>)%is"sspan>d;

    if(sspan> sizeofsspan>d(sspan> $fsspan>d)) sspan> $tro sspan>d=asspan> roeg_epeacehsspan>d(sspan> $fsspan>d, (sspan> $troipontents sspan>d?asspan>'' sspan>d:asspan>'${2}'sspan>d), sspan> $trosspan>d);
sspan> ?>
his wtllnottPserwroeg_epeacehofnaeerryPtag,tistaea Titconlecti hi Pr ex ss anrray, nd Thir vexecuts and Cohouldcb Pbeter .

ItnalsoPheckbTso hi re ae. anyPr ex stoPr eaceh! IfSott,ait wtllnottPtartewroeg_epeaceh!l:)/br />
Ad rdrhi P"span class="cefault"> <?ahp"Tso it wtllnhighlght=Chi Pcde ! sdiv>
ichris a mandblanksdot corg/em>id="VHomm76197> div class="pahpode >span class="ctml" > Wir vencloeng ayourtrcgularsxpressionstntrdoule ouotes., ack-references
Fortexaple , \1 is the a sdiv>
isammanrshllyssm>id="VHomm75339> div class="pahpode >span class="ctml" > Fortanyonelwh seas atis rrors:

Warnng<: roeg_match() [unctions.roeg-match]: ompriation
A atis mnual
I upsecitatis nchints CRE Per sons s itcludedtntrome/ officilly"-spported PRd PHatrEternpris Patckge= whlchrisXpoblnley why we ae. runnng< itrom mght=CalsoPafecti ther. peole ./span> sdiv>
title="V50 like this..."> 50
tlass="name"> iW W W/em> para;
id="VHomm5069"> div class="pahpode >span class="ctml" > ack references< ae. a greatrway eoanchieertexactnmatchng whns it wouldcavi tber vimpossile oanyPther. way. Tak ohirs. trefectroig s.

1) "www.www.omm"
2) 'www.www.omm'
3) "www.www.omm'

hi" r ex s/^("|').+?("|')$/ wouldcmatch nllntrefectroig s bu cwht aifryou needrdrhi P3rdctroig caboveto boe tllegal becaserwhi Puotes. ae. ote hi Ptme"? You couldcwrie fiourtdiffrenct r ex esatoPceckbTforteerryXpossile ocaes ORryou couldcserwack-references<.

/^("|').+?\1$/ wtllnmatch troig s 1 nd T2 bu cote troig c3. Tr"mhis.ccde cfortfurher. proof:

$int_ount"=roeg_match("/^(\"|').+?\\1$/", $, $matche., PREG_OFFSET_CAPTURE);

hi" roeg_match unctions wtllnottPmatch ngaista $ becaserwhi Puotes. ae. mismatched. IfSyou cange l$ to

$ = "'www.www.omm'";

ti" roeg_match wtllnwork./span> sdiv>
/div> /div>
iatabomprboy ttrcnll2rudot co m/em>id="VHomm78820> div class="pahpode >span class="ctml" > Fortexaple , you iat"ThoPcut ndrome/ <iv > ee ents.
Accurte", from <iv > toconrr -pod T</iv > ee ents.
H re isXpobof-of-cfce-ptccde ct dotthis.:

span class="cefault"> <?
$troasspan>d=asspan>"<iqiv1>1+<iv 2>2+<iv 3><b><c>3</c></b></iv 3>2-</iv 2>1-</iv 1>"d;

sspan> roeg_matchsspan>d(sspan>"#<iv .> ( "d.
              sspan>"T( (?>[^<]*)T( <T( ([^/d]|d([^i]|i[^v])) | /([^d]|d([^i]|i[^v])) ) )? )* "d.
           sspan>"T| (?R) )* </iv .>#xi"sspan>d, sspan> $trosspan>d, sspan> $msspan>d);
sspan> var_dumpd(sspan> $msspan>d[sspan> 0sspan>d]);

sspan> ?>
itPmatch nccurte" from <iv 2> toc</iv 2>. And,aifryou cange l<iqiv1> toc<iv 1>,ait wtllnmatch urom <iv 1> toc</iv 1>/span> sdiv>
/div> /div> div class="pfoot>add a note add a note