So if you use the $this->escapeHtml() -method in a template in Magento, you might have come across an error something like this:
1 2 3 4 5 6 |
Warning: htmlspecialchars() [function.htmlspecialchars]: Invalid multibyte sequence in argument in /path/to/app/code/core/Mage/Core/Helper/Abstract.php on line 221 #0 [internal function]: mageCoreErrorHandler(2, 'htmlspecialchar...', '/path/to/...', 221, Array) #1 /path/to/app/code/core/Mage/Core/Helper/Abstract.php(221): htmlspecialchars('My?String...', 2, 'UTF-8', false) ... etc ... |
The problem here is a bug in older PHP versions where the combination of display_errors=off and multibyte string throws this error (yeah that’s right…).
The fix is rather simple. Instead of directly passing your value to this method, utf8_encode() it first:
1 |
echo $this->escapeHtml(utf8_encode($_value)); |
That should get rid of this nasty little bugger!
How would you rate this article?
★ ★ ★ ★ ★