Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2008-05-29 12:35:04

MarcoK
Plugin Author
From: Como
Registered: 2006-10-17
Posts: 248
Website

Backreferencing for plugin

Hi at all.

I’m writing a plug-in and i have a trouble with regexp.

I parse the $thisarticle[‘body’], with this expr:

preg_match_all(‘#<([a-z0-6]+) class=“prova”>(.*?)</([a-z0-6]+)>#s’, $corpo, $tags).

I must find all tags and his content that have a class attribute named ‘prova’.

So the regexp function if in the content there is not a close tags.

Ex. <p class=“prova”>Hi my dear frend</p> will return true and entire string.

Ex. <p class=“prova”>Hi my <b>dear</b> frend</p> will return true but only to </b>

Did you know some solution?

tnks

Offline

#2 2008-05-29 17:07:49

ruud
Developer Emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
Website

Re: Backreferencing for plugin

Try this (the \1 part is set to whatever matches between the first set of () at the beginning):

preg_match_all('#<([a-z0-6]+) class="prova">(.*?)</\1>#s', $corpo, $tags).

Note that this only works if the only nested tags are something other than the one having the prova class, so when you try it on the example below, it will not return the last </div> (can’t be solved with a pure regex solution):

<div class="prova"><div>something</div></div>

Last edited by ruud (2008-05-29 17:23:47)

Offline

#3 2008-05-30 05:44:08

MarcoK
Plugin Author
From: Como
Registered: 2006-10-17
Posts: 248
Website

Re: Backreferencing for plugin

Thank you ruud.
I have used you suggestion.

I have made a plug-in for integrate into an article a multi language.

And in the first time that i tried to use, it work well.

it was in use into the home page of this site: www.cas-casalegno.it
If you change the the language, the NEWS, change.
the only things that not will change is the title of article.

tanks.

Last edited by MarcoK (2008-05-30 05:45:10)

Offline

Board footer

Powered by FluxBB