ThomasJSmart
Programmer
- Sep 16, 2002
- 634
Hi,
the variables and options of preg_match_all are giving me a headache again![Smile :) :)](data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7)
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:
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!
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!