Skip to content

htmlentities() in PHP ohne HTML-Tags zu zerstören

by Beni on Februar 26th, 2010

Hier meine Lösung für das Problem: :-)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
function htmlentitiesOutsideHTMLTags ($htmlText)
{
	$matches = Array();
	$sep = '###HTMLTAG###';
 
	preg_match_all("@<[^>]*>@", $htmlText, $matches);	
	$tmp = preg_replace("@(<[^>]*>)@", $sep, $htmlText);
	$tmp = explode($sep, $tmp);
 
	for ($i=0; $i<count($tmp); $i++)
		$tmp[$i] = htmlentities($tmp[$i]);
 
	$tmp = join($sep, $tmp);
 
	for ($i=0; $i<count($matches[0]); $i++)
		$tmp = preg_replace("@$sep@", $matches[0][$i], $tmp, 1);
 
	return $tmp;
}

Das wird dich vielleicht auch interessieren:

From → Allgemeines

No comments yet

Leave a Reply

Note: XHTML is allowed. Your email address will never be published.

Subscribe to this comment feed via RSS