V
V
Vladislav Petrenko2017-09-19 10:21:50
IDE
Vladislav Petrenko, 2017-09-19 10:21:50

What editor or IDE on a Mac can save a document as "UTF-8 without BOM"?

I myself work in Coda 2, but there is no function to save without BOM (Well, or I overlooked it).
Tell me in which editors or IDEs can I save a document as UTF-8 without BOM?
SOLUTION
Added a document with code to the root of the site

<?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;
 
// 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; 
}
?>
<!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>';
?>
</body>
</html>

And then I opened this file in the browser and it cleared all the BOM for me

Answer the question

In order to leave comments, you need to log in

5 answer(s)
S
Sergey Sokolov, 2017-09-19
@Strebend

I work constantly in Coda 2.6.6
BOM bytes are not assigned at the beginning of UTF-8 files. Checked xxd -b filename.ext
It is generally not recommended to set BOM for UTF-8 encoding, and Coda follows this recommendation.
For UTF encodings greater than 8, Coda has byte order selection options, they are disabled by default:
db79947308334048b1d24a59d79125a2.png

V
Vladislav Gaiduk, 2017-09-19
@Danan

sublime text

Z
zorca, 2017-09-19
@zorca

PHPStorm

A
Andrey Sanych, 2017-09-19
@mountpoint

PhpStorm, I think in WebStorm the same way
1505806013.png

V
Valentine, 2017-09-19
@vvpoloskin

And what, in macos VIM is not present?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question