This problem occures, because one of SugarCRM's system file is saved in UTF-8 + BOM encoding (usually it's config.php, but can be any other file, that was edited by administrator of portal).
This small php script will help you to find files with BOM:
PHP Code:
<?php
$bad_files = array();
$directory = "."; // Current directory
$fix_file = FALSE; // Change to TRUE, if you want to automatically fix files with BOM mark
$recursive_check = TRUE;
scanDirectory($directory, $bad_files);
if (count($bad_files) > 0)
{
echo "<br><br><br>Found the following files with a bad BOM:<br>";
printResults($bad_files);
}
else
echo "No Errors Found";
function scanDirectory($directory, &$bad_files)
{
global $recursive_check;
$skip_directories = array(".", "..", "cache");
if ($handle = opendir($directory))
{
echo "Checking Directory: $directory<br>";
while (false !== ($file = readdir($handle)))
{
$fullFile = $directory . DIRECTORY_SEPARATOR . $file;
// Recursive Call for sub-directories.
if (is_dir($fullFile) && $recursive_check)
{
if (in_array($file, $skip_directories))
Continue;
scanDirectory($fullFile, $bad_files);
}
if (checkFile($fullFile, $file))
$bad_files[] = $fullFile;
}
closedir($handle);
}
}
function checkFile($file, $fileOnly)
{
global $fix_file;
if (!is_file($file))
return;
if (substr($fileOnly, -4) == ".log")
return;
echo " $fileOnly";
$isBad = FALSE;
$file_contents = file_get_contents($file, "+r");
$hex = bin2hex($file_contents);
$first_token = substr($hex, 0, 6);
if ($first_token == 'efbbbf')
{
$isBad = TRUE;
echo " ...FOUND ERROR<br>";
if ($fix_file)
fixFile($hex,$file);
}
else
echo " ...OK<br>";
return $isBad;
}
function printResults($results)
{
foreach ($results as $fileName)
echo "$fileName<br>";
}
function fixFile($hex, $file)
{
$fp = fopen($file, 'w');
$good = substr($hex, 6);
$good_string = pack('H*', $good);
fwrite($fp, $good_string);
fclose($fp);
}
?>
Just create some php file in root directory of your SugarCRM portal (for example, fixbom.php). Paste there provided code and then open it thru browser.
When the script will finish it's work - it will show you list of files with BOM mark (at the end of page).
Then you can fix those files manually (change encoding to UTF-8 instead of UTF-8 + BOM) or automatically - replacing $fix_file with TRUE in the beginning of script.
P.S.
Source code were taken and slightly modified from Andreas Sandberg (http://developers.sugarcrm.com/wordp...n-eval-errors/)
Bookmarks