Regexp problem
| From: | Ronan Chilvers | Date: | Thu, 10 Apr 2003 13:11:31 +0000 |
| Subject: | Regexp problem | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-26987@lists.php.net to get a copy of this message | ||
Hi folks
My regexps aren't great !! Here's what I'm trying to do:-
1. Grab a list of book titles out of a table
2. Grab a block of text out of a table
3. Search the block of text for each of the titles and if its found replace the raw phrase with a
hyperlinked version.
So I need to find exact matches for phrases that have NOT already been hyperlinked. I'm using
preg_match() and preg_replace() so that I can have case insensitivity. Here's the regexp I
have now
$find="/\b".preg_quote($thetitle)."(?!.*<\/a>)/i";
$find is then plugged into preg_replace() with a $rep string which is the hyperlinked version of
$thetitle.
This is supposed to use a look-ahead to check that $thetitle is NOT followed by an </a>.
However it doesn't get all the titles, only some. A list like
title1, title2, title3, title4, title5, title6 has titles 2, 5, 6 hyperlinked but not 1, 3, 4.
Anyone see any immediate problems with my regexp ? (be gentle!!) Or can anyone suggest a regexp
that will find a string (case insenstive) in a block of text that is NOT surrounded by an <a>
tag ?
Headaches all round ... or at least for me ....
Cheers
--
Ronan
e: ronan@thelittledot.com
t: 01903 739 997
w: www.thelittledot.com
The Little Dot is a partnership of
Ronan Chilvers and Giles Webberley