Hallo,
es ist etwas seltsam, aber ich weiß nicht weiter. "htmlspecialchars()" funktioniert nicht, wenn es im HTML <head> verwendet wird, im <body> schon.
Zuerst dachte ich, vielleicht liegt es nur an den Browsern, aber der W3 Validator bemängelt es auch.
Mit var_dump wird der String korrekt angezeigt. Zudem wird die nächste Zeile dadurch auch beeinflußt, komischerweise, aber die übernächste schon nicht mehr.
Im <body> wird es korrekt ausgegeben.
es ist etwas seltsam, aber ich weiß nicht weiter. "htmlspecialchars()" funktioniert nicht, wenn es im HTML <head> verwendet wird, im <body> schon.
Zuerst dachte ich, vielleicht liegt es nur an den Browsern, aber der W3 Validator bemängelt es auch.
Code:
<head> <title><?php echo (htmlspecialchars($mytitle)); ?></title> <title>Cat's and "Dogs"</title> <meta name="description" content="<?php echo substr(htmlspecialchars(strip_tags($mydesc)), 0, 100); ?> ..." /> <meta name="description" content="Big Cat's and "Dogs" playing with little Cat's and "Dogs" in the ..." /> </head>
Mit var_dump wird der String korrekt angezeigt. Zudem wird die nächste Zeile dadurch auch beeinflußt, komischerweise, aber die übernächste schon nicht mehr.
Code:
<head> <title><?php var_dump(htmlspecialchars($mytitle)); ?></title> <title>string(xx) "Cat's and "Dogs""</title> <meta name="description" content="<?php echo substr(htmlspecialchars(strip_tags($mydesc)), 0, 100); ?> ..." /> <meta name="description" content="Big Cat's and "Dogs" playing with little Cat's and "Dogs" in the ..." /> <meta property="og:title" content="<?php echo (htmlspecialchars($mytitle)); ?>" /> <meta property="og:title" content="Cat's and "Dogs"" /> </head>
Im <body> wird es korrekt ausgegeben.
Code:
<body> <?php echo htmlspecialchars($mytitle); ?> Cat's and "Dogs" <?php echo htmlspecialchars(strip_tags($mydesc)); ?> Big Cat's and "Dogs" playing with little Cat's and "Dogs" in the Garden. </body>
Kommentar