Okay I might not be going about this the right way, but here goes..
I have this string that takes a link and extracts the text between the tags...
$string = $item;
$pattern = '/\<a([^>]*)\>([^<]*)\<\/a\>/i';
$replacement = '$2';
$message = preg_replace($pattern, $replacement, $string);
There are a few items in this string that have ampersands (in the text portion, not the tag portion), however most don't. I'm trying to figure out a way to either incorporate the ampersand into the current pattern or do another preg_replace on the $message
to remove the ampersand after the tags are striped away.
THANKS!
Do you want to remove everything after the ampersand? Then it's
'/\<a([^>]*)\>([^<&]*)[^<]*\<\/a\>/i';
Otherwise, you'll need a 2nd operation.
BTW: Your regex will also match other tags starting with <a
, such as the <author>
or the <audio>
tag.
There's always $message = str_replace('&', '', $message);
Incidentally, if you are trying to strip tags from html input, there is also strip_tags
for example, if your input is
$text = '<a href="google.com">Text</a>';
Then strip_tags($text)
will produce Text
.