Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

preg_match_all

Status
Not open for further replies.

ThomasJSmart

Programmer
Sep 16, 2002
634
Hi,

the variables and options of preg_match_all are giving me a headache again :)

i was wondering if anyone could help me with the following:


i need to find WORD in STRING.

- STRING is a page of html text

- WORD is always 1 single query and will have letters, numbers and/or special chars like ë

- WORD must not be within an A or DIV tag in STRING


after i have found an array of WORDS im going to replace them with CODE_WORD_CODE. This part is all working. And this is what i have for the preg so far:

Code:
$regex1 = ">[^<]*(";
$regex2 = ")[^<]*<";
preg_match_all("/".$regex1.$word.$regex2."/i", $string, $matches, PREG_PATTERN_ORDER);

as you can see im just missing the part where WORD should not be within an A or DIV tag...

ok: WORD <div para='bla'>bla</div> <- this i have
not ok: bla <div para='bla'>WORD</div> <- HOW ???
not ok: bla <div para='WORD'>bla</div> <- this i have

ok: WORD <a href='bla'>bla</a> <- this i have
not ok: bla <a href='bla'>WORD</a> <- HOW ???
not ok: bla <a href='WORD'>bla</a> <- this i have



Thank you

I learned a bit yesterday, today i learned a lot, imagine what i'll learn tomorrow!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top