]*>.*?~is', '', $value) ?? $value; // Preserve word boundaries before stripping markup. $text = preg_replace('~<(?:br\b[^>]*|/p|/div|/li|/h[1-6]|/tr)>~i', "\n", $text) ?? $text; // phpcs:ignore WordPress.WP.AlternativeFunctions.strip_tags_strip_tags -- Standalone-test fallback is used only when WordPress is unavailable. $stripped = function_exists('wp_strip_all_tags') ? wp_strip_all_tags($text) : \strip_tags($text); $text = html_entity_decode($stripped, ENT_QUOTES | ENT_HTML5, 'UTF-8'); $text = preg_replace('~(?:https?://|www\.)[^\s<>]+|[\w.+-]+@[\w.-]+\.[a-z]{2,}~iu', '', $text) ?? $text; $parts = preg_split('/\R+|(?<=[.!?])\s+/u', $text) ?: []; $kept = []; foreach ($parts as $part) { $part = trim((string) preg_replace('/[ \t]+/u', ' ', $part)); // Cut vendor notices even when appended to product prose. $part = preg_replace('/(?:\s*[-–|]\s*)?(?:Prestalia\s+e-commerce\s+solutions|powered by\b|venduto da\b|sold by\b|fonte\s*:|source\s*:|descrizione (?:fornita|tratta) da\b|description (?:provided|taken) (?:by|from)\b|il prodotto verrà spedito\b|spedizione gratuita\b|free shipping\b|buyer protection\b|fast shipping\b|visita il nostro\b|visit our\b|contattaci\b|contact us\b|acquista (?:ora|sul nostro)\b|buy now\b).*$/iu', '', $part) ?? $part; $part = trim($part, " \t\n\r\0\x0B-–|"); if ($part === '') { continue; } if ($title !== '' && str_starts_with($part, $title . ' ')) { $part = trim(substr($part, strlen($title))); } if ($part !== '' && !in_array($part, $kept, true)) { $kept[] = $part; } } return trim(implode("\n", $kept)); } }