Author Topic: Virtuemart is adding &#65279 before content? Solution: remove BOM  (Read 26597 times)

hmmm

  • Beginner
  • *
  • Posts: 11
Hey,

I've recently upgraded to 2.02 and encountering a problem. I'm not sure if it has to do with the upgrade or me fiddling with it, but I'm unable to find the cause of the problem :(.

The problem is that there is appearing &#65279 &#65279 before any virtuemart content. This is the html of the default webshop page: (no template overruling)
Code: [Select]
<div class="content_right webshop">
<div id="system-message-container"> </div>
&#65279;&#65279;
<div class="category-view">
<div class="featured-view">
<div class="latest-view">
<div class="topten-view">
</div>

Other pages on the website are not having this issue, so I don't think it's related to my template's index.php, but here the include anyway:
Code: [Select]
    <?php if($main_content): ?>
        <jdoc:include type="message" />
<jdoc:include type="component" />
    <?php endif; ?>

I hope somebody can help me with finding the cause of those extra spaces/newlines. They are really frustrating me, since I'm unable to find the cause :(.

cutemarit

  • Beginner
  • *
  • Posts: 1
Re: Virtuemart is adding &#65279 before content?
« Reply #1 on: February 28, 2012, 07:46:06 am »
I found the same problem as you and the following method is how I fixed mine. Those characters are something about Byte Order Mark (BOM) which I found that on google so what I've done is use a program that can detect which file has BOM in it and try to remove BOM from those files (I use 'File Bom Detector') and my problems was solved.
By the way, I found the following files have BOM
  • administrator/components/com_virtuemart/views/category/tmpl/edit_category/form.php
  • administrator/components/com_virtuemart/tables/categories.php
  • administrator/components/com_virtuemart/tables/products.php
Hope it can help you

hmmm

  • Beginner
  • *
  • Posts: 11
Re: Virtuemart is adding &#65279 before content?
« Reply #2 on: February 28, 2012, 11:32:05 am »
Thank you very very much  :). I see it's your first post, thanks for registering and helping me out!

The problem was indeed the bom characters. I have no idea how they got there, very strange.

For the linux users, here is what I was able to scratch together to find the files with bom-character and fix it. Real hackers/geeks could do it way better, but it does the job :).

Find the files with the bom character:
Code: [Select]
find /var/www/website/ -type f -print  -exec hd -n 3 {} \;  | grep -1 "ef bb bf" | grep "some_part_of_the_path" > bom_lines.txt

Next remove the bom character:
Code: [Select]
while read l; do sed -i '1 s/^\xef\xbb\xbf//'   $l ; done < bom_lines.txt

A list of the files containing those bom characters:
Code: [Select]
components/com_virtuemart/assets/css/vmsite-ltr.css
components/com_virtuemart/assets/js/languages/jquery.validationEngine-es.js
modules/mod_dn/language/ru-RU/ru-RU.mod_dn.ini
modules/mod_virtuemart_product/back/tmpl/default.php
modules/mod_virtuemart_product/mod_virtuemart_product.php
modules/tmp/mod_virtuemart_product/back/tmpl/default.php
modules/mod_minifrontpage/mod_minifrontpage.xml
administrator/components/com_virtuemart/tables/products.php
administrator/components/com_virtuemart/tables/categories.php
administrator/components/com_virtuemart/views/category/tmpl
administrator/language/nl-NL/nl-NL.com_virtuemart.sys.ini
administrator/language/nl-NL/nl-NL.plg_vmpayment_paypal.ini
administrator/language/nl-NL/nl-NL.plg_vmshipment_weight_countries.ini
administrator/language/en-GB/en-GB.mod_virtuemart_product.ini
administrator/language/en-GB/en-GB.mod_virtuemart_currencies.ini
administrator/language/en-GB/en-GB.mod_virtuemart_manufacturer.ini
administrator/language/en-GB/en-GB.plg_vmcustom_specification.ini
administrator/language/th-TH/th-TH.com_virtuemart.sys.ini
administrator/language/th-TH/th-TH.com_virtuemart.ini
administrator/language/fr-FR/fr-FR.plg_vmcustom_specification.ini
administrator/language/fr-FR/fr-FR.plg_vmcustom_download.ini
administrator/language/sv-SE/sv-SE.plg_vmcustom_specification.ini
administrator/language/es-ES/es-ES.plg_vmcustom_specification.ini
administrator/language/de-DE/de-DE.plg_vmcustom_specification.ini
language/nl-NL_old/nl-NL.com_virtuemart.sys.ini
language/nl-NL_old/nl-NL.mod_virtuemart_currencies.ini
language/nl-NL_old/nl-NL.mod_virtuemart_cart.ini
language/nl-NL_old/nl-NL.mod_virtuemart_search.ini
language/nl-NL_old/nl-NL.mod_virtuemart_product.ini
language/nl-NL_old/nl-NL.mod_virtuemart_manufacturer.ini
language/nl-NL/nl-NL.com_virtuemart.sys.ini
language/nl-NL/nl-NL.mod_virtuemart_currencies.ini
language/nl-NL/nl-NL.mod_virtuemart_cart.ini
language/nl-NL/nl-NL.mod_virtuemart_search.ini
language/nl-NL/nl-NL.mod_virtuemart_product.ini
language/nl-NL/nl-NL.mod_virtuemart_category.ini
language/nl-NL/nl-NL.mod_virtuemart_manufacturer.ini
language/en-GB/en-GB.com_virtuemart.ini
language/th-TH/th-TH.com_virtuemart.ini
language/ru-RU/ru-RU.mod_virtuemart_currencies.ini
language/fr-FR/fr-FR.mod_virtuemart_category.sys.ini

Credit for the hd and sed tricks: http://stackoverflow.com/questions/1068650/using-awk-to-remove-the-byte-order-mark

corymp

  • Jr. Member
  • **
  • Posts: 149
Re: Virtuemart is adding &#65279 before content?
« Reply #3 on: March 01, 2012, 04:25:43 am »
I'm having the same trouble. I have &#65279;  below where <jdoc:include type="component" /> appears in my template. It leaves a blank line above the content area on my site. I've tried notepad++ but I can't find the right file. I'm on windows so no linux commands will help..
VM 2.0.4 Stable
J2.5.4

hmmm

  • Beginner
  • *
  • Posts: 11
Re: Virtuemart is adding &#65279 before content?
« Reply #4 on: March 01, 2012, 10:25:30 am »
Those characters are something about Byte Order Mark (BOM) which I found that on google so what I've done is use a program that can detect which file has BOM in it and try to remove BOM from those files (I use 'File Bom Detector') and my problems was solved.

The prorgam Cutemarit mentions is for windows. If you google for it, you'll find it, or some alternatives :).

corymp

  • Jr. Member
  • **
  • Posts: 149
Re: Virtuemart is adding &#65279 before content?
« Reply #5 on: March 01, 2012, 23:34:59 pm »
Found a solution!

Copy this code to say bom.php, upload to root and run it.

It will scan and remove BOM from all pages. Fixed my problem instantly.

Make sure to backup beforehand as a precaution.

Code: [Select]
<?php 
// Tell me the root folder path.
// You can also try this one
// $HOME = $_SERVER["DOCUMENT_ROOT"];
// Or this
// dirname(__FILE__)
$HOME dirname(__FILE__);

// Is this a Windows host ? If it is, change this line to $WIN = 1;
$WIN 0;

// That's all I need
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>UTF8 BOM FINDER and REMOVER</title>
<style>
body { font-size: 10px; font-family: Arial, Helvetica, sans-serif; background: #FFF; color: #000; }
.FOUND { color: #F30; font-size: 14px; font-weight: bold; }
</style>
</head>
<body>
<?php
$BOMBED 
= array();
RecursiveFolder($HOME);
echo 
'<h2>These files had UTF8 BOM, but i cleaned them:</h2><p class="FOUND">';
foreach (
$BOMBED as $utf) { echo $utf ."<br />\n"; }
echo 
'</p>';

// Recursive finder
function RecursiveFolder($sHOME) {
  global 
$BOMBED$WIN;
  
  
$win32 = ($WIN == 1) ? "\\" "/";
  
  
$folder dir($sHOME);
  
  
$foundfolders = array();
  while (
$file $folder->read()) {
    if(
$file != "." and $file != "..") {
      if(
filetype($sHOME $win32 $file) == "dir"){
        
$foundfolders[count($foundfolders)] = $sHOME $win32 $file;
      } else {
        
$content file_get_contents($sHOME $win32 $file);
        
$BOM SearchBOM($content);
        if (
$BOM) {
          
$BOMBED[count($BOMBED)] = $sHOME $win32 $file;
          
          
// Remove first three chars from the file
          
$content substr($content,3);
          
// Write to file 
          
file_put_contents($sHOME $win32 $file$content);
        }
      }
    }
  }
  
$folder->close();
  
  if(
count($foundfolders) > 0) {
    foreach (
$foundfolders as $folder) {
      
RecursiveFolder($folder$win32);
    }
  }
}

// Searching for BOM in files
function SearchBOM($string) { 
    if(
substr($string,0,3) == pack("CCC",0xef,0xbb,0xbf)) return true;
    return 
false
}
?>

</body>
</html>
VM 2.0.4 Stable
J2.5.4

PRO

  • Global Moderator
  • Super Hero
  • *
  • Posts: 10365
  • VirtueMart Version: 3+
Re: Virtuemart is adding &#65279 before content?
« Reply #6 on: March 02, 2012, 02:10:37 am »
Just download the newest files.
https://dev.virtuemart.net/svn/virtuemart/trunk/virtuemart/

They are fixed
J3.9+ VM 3.4.2
Slowest Page Speed Score (88) (Category)
Fastest Page Speed Score (94-96) (productdetails)

rayge

  • Jr. Member
  • **
  • Posts: 189
Re: Virtuemart is adding &#65279 before content?
« Reply #7 on: March 04, 2012, 18:47:15 pm »
Thanks corymp

I dont have time to setup SVN so this was a good shortcut until they release a new version for download or I DO have time to grab SVN.
looks placing your file in
administrator/components/com_virtuemart/
and running it was enough to fix it for me.
although its possible there are more of thoses items else where there was no need to run it on the whole site. to fix the issue for me.
I Use: Joomla 3.4.1 & VM 3.0.9

erik.demartiis

  • Beginner
  • *
  • Posts: 12
Re: Virtuemart is adding &#65279 before content?
« Reply #8 on: March 08, 2012, 14:58:21 pm »
Found a solution!
Copy this code to say bom.php, upload to root and run it.
It will scan and remove BOM from all pages. Fixed my problem instantly.
Make sure to backup beforehand as a precaution.

Perfect! It works!
Thank you a lot.
Erik

mpulse

  • Beginner
  • *
  • Posts: 15
Re: Virtuemart is adding &#65279 before content?
« Reply #9 on: April 03, 2012, 10:26:58 am »
YES worked for me just fine!!! THX !!!

lyusida

  • Beginner
  • *
  • Posts: 1
Re: Virtuemart is adding &#65279 before content?
« Reply #10 on: April 28, 2012, 12:34:55 pm »
Quote
Found a solution!
Copy this code to say bom.php, upload to root and run it.
It will scan and remove BOM from all pages. Fixed my problem instantly.
Make sure to backup beforehand as a precaution.

Спасибо огромное!!! Не могла ничего найти на русскоязычных сайтах. Ваш скрипт помог сразу. Thanks!!! =)

julos08

  • Beginner
  • *
  • Posts: 34
Re: Virtuemart is adding &#65279 before content?
« Reply #11 on: April 27, 2017, 15:33:09 pm »
Quote
Found a solution!
Copy this code to say bom.php, upload to root and run it.
It will scan and remove BOM from all pages. Fixed my problem instantly.
Make sure to backup beforehand as a precaution.

5 years ago and this code still working for me. MANY THANKS !!!