1){ $lastGroup = array_pop($groups); } $number = implode('', $groups); return (strlen($lastGroup) < 3) ? floatval($number.'.'.$lastGroup) : floatval($number.$lastGroup); } public static function sanitize($string, $force_lowercase = true, $anal = false, $substr = false) { $strip = array("~", "`", "!", "@", "#", "$", "%", "^", "&", "*", "(", ")", "_", "=", "+", "[", "{", "]", "}", "\\", "|", ";", ":", "\"", "'", "‘", "’", "“", "”", "–", "—", "—", "–", ",", "<", ".", ">", "/", "?"); $clean = trim(str_replace($strip, "", strip_tags($string))); $clean = preg_replace('/\s+/', "_", $clean); $clean = ($anal) ? preg_replace("/[^a-zA-Z0-9]/", "", $clean) : $clean ; if($substr){ $clean = (strlen($clean) > 33) ? substr($clean,-33) : $clean; } return ($force_lowercase) ? (function_exists('mb_strtolower')) ? mb_strtolower($clean, 'UTF-8') : strtolower($clean) : $clean; } public static function replacePlaceholders($search, $replace){ preg_match_all("/\{{(.+?)\}}/", $search, $matches); if (isset($matches[1]) && count($matches[1]) > 0){ foreach ($matches[1] as $key => $value) { $kvalue = trim($value); if (array_key_exists($kvalue, $replace)){ $search = preg_replace("/\{\{$value\}\}/", $replace[$kvalue], $search); } } } return $search; } public static function cleanHTML($html) { $html = str_replace('font-size: 14px;', ' ', $html); $html = str_replace('font-weight: lighter; ', ' ', $html); $html = str_replace('font-family: Helvetica, Arial, sans-serif; ', ' ', $html); $html = str_replace('font-family: Verdana, sans-serif; ', ' ', $html); $html = str_replace('color: rgb(60, 60, 60); ', ' ', $html); $html = str_replace(' style=" padding: 0px; margin-right: 0px; margin-left: 0px; margin-bottom: 20px !important; line-height: 20px !important;"', ' ', $html); $html = str_replace('property="article"', ' ', $html); $html = str_replace(' ', ' ', $html); $html = str_replace('https://www.aegypten-online.de', 'https://www.sterntours.de', $html); $dom = new \DOMDocument('1.0', 'utf-8'); @$dom->loadHTML(mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8')); $removeFullTags = ['span', 'a']; foreach ($removeFullTags as $removeFullTag){ $domElemsToRemove = []; $elements = $dom->getElementsByTagName($removeFullTag); foreach ($elements as $element) { $domElemsToRemove[] = $element; } foreach ($domElemsToRemove as $domElem) { if($removeFullTag == 'span' && strpos($domElem->getAttribute('style'), 'font-weight: 700') !== false){ $new_node = $dom->createTextNode("".$domElem->nodeValue.""); }else{ $new_node = $dom->createTextNode($domElem->nodeValue); } $domElem->parentNode->replaceChild($new_node, $domElem); } } $removeStyleTags = ['ul', 'li', 'h1', 'h2', 'br']; foreach ($removeStyleTags as $removeStyleTag){ $elements = $dom->getElementsByTagName($removeStyleTag); foreach ($elements as $element) { $element->removeAttribute('style'); } } $html = $dom->saveHTML(); return $html; } }