NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

<?php
// http://wallot/test/maj.php


// start with PHP: result always "ANSI" or "UTF-8"
// one step further on Java side: check byte order marks of utf-8 and utf-16 le/be
// put count in a variable before it enters the loop
//converting string to binary
function strToBin($input){
if (!is_string($input))
return false;
$value = unpack('H*', $input);
return base_convert($value[1], 16, 2);
}

//checkFileEncoding function checks the encoding of the file
//@params : $filename: the name or link to the file
// $limit: provide a number to limit the matches of Umlauts .. by default : 2
function checkFileEncoding($filename,$limit = 2){

echo "Checking encoding for file : ",realpath($filename),"<br>";
//getting the file
$file = fopen($filename,'rb');
// creating array to hold binary values of the imported file
$result = array();
//byteArray Array holds binary values of Ä,ä,Ü,ü,Ö,ö,ß
$byteArray = array(
"11000011 10000100",// Ä
"11000011 10100100",// ä
"11000011 10011100",// Ü
"11000011 10111100",// ü
"11000011 10010110",// Ö
"11000011 10110110",// ö
"11000011 10011111" // ß
);

//lcount{lines count} limited to 100 lines only
$lcount = 0;
while($line = fgets($file)){
$line = trim(preg_replace('/s+/', ' ', $line));
if(empty($line))
continue;
$lcount++;
if($lcount <= 100)
for($i=0;$i<strlen($line);$i++){
$result[] = strToBin($line[$i]);
}
}
echo "<br>- line count : {$lcount}";
//$match counts how much umlauts in the file
$match = 0;
//define compinter array holds two bytes in one string in the array separated with space
$combiner = array();
$resultCount = count($result);
//comparing two arrays $byteArray and $result
for($i =0;$i<$resultCount; ){
//all of the umlauts binarys and other symbols start with 11
if($result[$i] != 11000011){
$i++;
continue;
} else {
//combining 2 cells of the array $result to match UTF-8 binary table
$combiner[] = $result[$i] ." ". $result[$i+1];
$i = $i+2;
}

}
foreach($combiner as $cvalue){
foreach($byteArray as $covalue){
if($cvalue == $covalue)
++$match;
}
}

//print_r($combiner);
//echo '<br><pre>',print_r($compiner),'</pre>';
echo $match > 0 ? "<br>- Umlaut match : {$match}" : "<br>- Umlaut match : no match found!";
if($match >= $limit)
echo "<br>- Encoding type of the file is "UTF-8"<br><br><hr>";
else echo "<br>- Encoding type of the file is "ANSI"<br><br><hr>";

//close file read stream
fclose($file);
}
checkFileEncoding("germancharansi.txt");
checkFileEncoding("germancharutf8.txt");
checkFileEncoding("englishchar.txt");
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.