[SOLVED] Warning: htmlspecialchars() expects parameter 1 to be string, array given in /includes/bootstrap.inc on line 860
One of the errors we come across in a Drupal 6 installation is "htmlspecialchars() expects parameter 1 to be string, array given in /includes/bootstrap.inc on line 860". This is an issue with the Internationalization and Taxonomy translation modules. This issue can be fixed by adding a line in the bootstrap.inc file. If you want to know how to solve the warning, continue reading.
- Edit includes/bootstrap.inc file and go to line 858.
- At present it will be like this
if ($php525) { return htmlspecialchars($text, ENT_QUOTES, 'UTF-8'); } return (preg_match('/^./us', $text) == 1) ? htmlspecialchars($text, ENT_QUOTES, 'UTF-8') : '';
- Change it to
if ($php525) { return (preg_match('/^./us', (string) $text) == 1) ? htmlspecialchars((string) $text, ENT_QUOTES, 'UTF-8') : ''; } return (preg_match('/^./us', $text) == 1) ? htmlspecialchars($text, ENT_QUOTES, 'UTF-8') : '';
- Flush all caches
If the steps mentioned above are followed correctly, "htmlspecialchars() expects parameter 1 to be string" warning would be fixed. Do note that this is only a work around and the right solution would be to find the exact place where the function is called and see what is passing $text as an array instead of a string and fix it there. This can be done by using debug_backtrace after checking for the type of $text.