[ale] Need help with a regular expression please....
Keith Morris
graphicsguy at charter.net
Mon Jul 28 16:02:07 EDT 2003
Hi all! I'm creating a specialized mini CMS in PHP that will store
content in a MySQL database. What I am trying to do is parse the
content and replace certain keywords with a link. The keywords and
associated links are kept in a MySQL table.
Here is an example.
$keyword = "Widgets Technology Co.";
$location = "http://www.widgets.com/about";
$keyword2 = "Widgets";
$location2 = "http://www.widgets.com";
$content = "We have the best Widgets at Widgets Technology Co.";
I want to parse through $content looking for $keyword and replacing it
with:
$keyword (this I can do with no problem)
but I am going to be looping through a series of keywords (phrases)
sorted by length (longest to shortest) that may or may not contain
other defined keywords such as the values above for $keyword2 which
would cause nested links and other nonsense.
so what I'm needing is a regular expression that will find the
$keyword (phrase) that is not already between "<a href =" and "</a>"
so that it will not try to relink it.
so far, this is the regular expression that I have, but does not work
properly:
[^(^\<a href=)][^(\>)]($keyword)[^(a\>)$]
If there is a better way of doing this, I would appreciate any
insights.
Thanks.
Keith Morris
_______________________________________________
Ale mailing list
Ale at ale.org
http://www.ale.org/mailman/listinfo/ale
More information about the Ale
mailing list