Ah, sorry, playing Crysis.
Code: Select all
preg_replace('/(<a\\b[^>]+?title\\s*=\\s*")([^"]+)("[^>]*>)/ie', '"$1" . strip_tags("$2") . "$3"', $text)
Here goes:
Code: Select all
(<a\b[^>]+?title\s*=\s*")([^"]+)("[^>]*>)
Three parts:
(<a\b[^>]+?title\s*=\s*")
- \b is a word boundary - matches a location (between a \w and a not-\w)
- [^>]+? is at least one character that isn't a > but matches as few as possible
- \s is whitespace (space, tab, newline, etc)
([^"]+)
- [^"]+ is at least one character that isn't a " and matches as many as it possibly can
("[^>]*>)
- [^>]* is some number (could be zero) of not-> characters. Also matches as many as possible
All together:
$1 is
<a, some number of not-> characters,
title, maybe some spaces,
=, maybe some more spaces, and a
".
$2 is some number of not-" characters.
$3 is a
", any number of not-> characters, and a
>.
The /i flag means to do a case-insensitive search (so it works with <A TITLE=""> too) and /e means that the replacement text is actually PHP code to evaluate.
preg_replace will replace $X with the captured subpattern (after slashes have been added) so the evaluated code could look something like
Code: Select all
"<a href=\"http://forums.devnetwork.net\" title=\"" . strip_tags("<b>DevNetwork Forums</b>") . "\" rel=\"external\">"