$str = \'some text tag contents more text \';
My questions are:
How to retrieve content tag contents
which is between
I tested this function, it works for nested tags too, use true/false to exclude/include your tags. Found here: https://www.php.net/manual/en/function.strip-tags.php
/si', trim($tags), $tags);
$tags = array_unique($tags[1]);
if(is_array($tags) AND count($tags) > 0) {
if($invert == FALSE) {
return preg_replace('@<(?!(?:'. implode('|', $tags) .')\b)(\w+)\b.*?>.*?\1>@si', '', $text);
}
else {
return preg_replace('@<('. implode('|', $tags) .')\b.*?>.*?\1>@si', '', $text);
}
}
elseif($invert == FALSE) {
return preg_replace('@<(\w+)\b.*?>.*?\1>@si', '', $text);
}
return $text;
}
// Sample text:
$text = 'sample text with tags';
// Result for:
echo strip_tags_content($text);
// text with
// Result for:
echo strip_tags_content($text, '');
// sample text with
// Result for:
echo strip_tags_content($text, '', TRUE);
// text with tags