public function testHtmlCharsDecode() { $this->assertEquals(htmlchars_decode('ja ha'), 'ja ha'); // TODO hex encode nbsp character $this->assertEquals(htmlchars_decode('reg®me'), 'reg®me'); $this->assertEquals(htmlchars_decode('''), "'"); }
/** similar to strip_tags() but also removes all javascript / css inside <script> or <style> tags */ function strip_html($s) { $search = array('@<!--' . '(?:' . '(?!-->)' . '.' . ')*' . '-->@si', '@<(script|style)[^>]*?>.*?</(script|style)>@si', '@<[\\/\\!]*?[^<>]*?>@si'); $s = preg_replace($search, '', $s); $s = htmlchars_decode($s); return $s; }
/** * reduce excessive whitespace to a single space */ function reduce_whitespace($s) { $s = htmlchars_decode($s); $s = str_replace("\t", ' ', $s); //tabs -> spaces $s = str_replace("\n", ' ', $s); //linefeed -> spaces $s = str_replace("\r", ' ', $s); //linefeed -> spaces do { $tmp = $s; $s = str_replace(' ', ' ', $s); } while ($s != $tmp); return trim($s); }