Use Encode::decode to decode your data from whatever encoding it's in to Perl's internal format.

Then, when writing the data out to a file, set the 'utf8' layer to make the data be written in UTF-8.

use Encode;

my $data_from_database = ...;

my $perl_data = decode('ISO-8859-1', $data_from_database);

binmode STDOUT, ':utf8';

print $perl_data;
Answer from zgpmax on Stack Overflow
🌐
CheckSERP
checkserp.com › encode › utf8
Utf-8 Converter, Utf-8 Encoding and Decoder | CheckSERP
Online Utf-8 converter, easy to use utf-8 encoding and decoder tool. Convert plain text to utf-8 codes and vice versa.
🌐
Browserling
browserling.com › tools › utf8-encode
UTF-8 Encode - Convert Text to UTF-8 - Online - Browserling Web Developer Tools
Useful, free online tool for that converts text and strings to UTF8 encoding. No ads, nonsense, or garbage, just a UTF8 encoder. Press a button – get the result.
🌐
Online Tools
onlinetools.com › unicode › convert-unicode-to-utf8
Convert Unicode to UTF-8 – Online Unicode Tools
This utility encodes Unicode text to UTF-8 encoding. It's free, gets the job done quickly, and it's entirely browser-based. Try it out!
🌐
University of Edinburgh
cogsci.ed.ac.uk › ~richard › utf-8.html
UTF-8 Tool
Some browsers may not be able to ... for some characters. Installing more fonts may help. Cutting and pasting does not work reliably in all browsers. When cutting and pasting hex numbers from dump output on little-endian machines (eg x86), beware of byte order problems. Hex numbers should not be prefixed with "0x", "U+", or anything else. Hex and octal UTF-8 byte input ...
🌐
Subtitle Tools
subtitletools.com › convert-text-files-to-utf8-online
Convert files to UTF-8: fix broken text encoding
This tool converts text files to unicode UTF-8. It fixes gibberish text, question marks, and mojibake. Supports all text and subtitle files.
🌐
Geekflare
geekflare.com › home › tools › utf-8 decoder & encoder
UTF-8 Decoder - Encode and Decode UTF-8 Text
The Geekflare tool lets you convert plain text into UTF-8 encoded format, or translate encoded text back into readable language. With a simple toggle switch, you can instantly swap between "Encode" and "Decode" modes depending on your task.
🌐
r12a
r12a.github.io › app-conversion
Unicode code converter
Helps you convert between Unicode character numbers, characters, UTF-8 and UTF-16 code units in hex, percent escapes,and Numeric Character References (hex and decimal).
Find elsewhere
🌐
Online Tools
onlinetools.com › utf8 › convert-ascii-to-utf8
Convert ASCII to UTF8 – Online UTF8 Tools
World's simplest online utility that converts ASCII to UTF8. Free, quick, and powerful. Import ASCII – get UTF8.
🌐
CodeShack
codeshack.io › home › tools › utf-8 encoder
UTF-8 Encoder - Convert Text to UTF-8 Bytes (Hex, Binary, Decimal)
Free UTF-8 encoder. Convert any text into its UTF-8 byte sequence in hexadecimal, binary or decimal, with custom separators, prefixes and hex case. Fast, private and 100% in your browser.
🌐
Unicodeconvert
unicodeconvert.com › utf8
Online UTF-8 Unicode Converter
🌐🧠 This free online tool lets you convert between human-readable text and its UTF-8 byte/escape representations for inspection, debugging, and learning. Encode text into UTF-8 byte sequences or Unicode escape entities. Decode UTF-8 bytes or escape sequences back into readable text. Inspect how ASCII, emojis, and international characters are actually stored.
🌐
PHP
php.net › manual › en › function.utf8-encode.php
PHP: utf8_encode - Manual
This function does not attempt to guess the current encoding of the provided string, it assumes it is encoded as ISO-8859-1 (also known as "Latin 1") and converts to UTF-8. Since every sequence of bytes is a valid ISO-8859-1 string, this never results in an error, but will not result in a useful string if a different encoding was intended. Many web pages marked as using the ISO-8859-1 character encoding actually use the similar Windows-1252 encoding, and web browsers will interpret ISO-8859-1 web pages as Windows-1252.
🌐
Testmu
testmu.ai › home › free tools › utf8 encode
CUTF8 Encode Online Tool | TestMu AI
You can encode and decode text in UTF-8 format online using various web-based tools and converters. Simply input your text and select the desired operation (encode or decode). ... Yes, most UTF-8 decoders are safe and secure.
🌐
SubExtractor
subextractor.com › tools › convert-to-utf8
Convert to UTF-8 - Free Online Text Encoding Converter - SubExtractor
Free online tool to convert text files from any encoding to UTF-8 for maximum compatibility.
Top answer
1 of 1
1

UTF-8 is a superset of ASCII so converting from ASCII to UTF-8 is like converting a car into a vehicle.

+--- UTF-8 ---------------+
|                         |
|   +--- ASCII ---+       |
|   |             |       |
|   +-------------+       |
+-------------------------+

The tool you link seems to be using the term "ASCII" as synonym for mojibake (it says "car" but means "scrap metal"). Mojibake typically happens this way:

  1. You pick a non-English character: 'WHITE MEDIUM DIAMOND' (U+2B26)

  2. You encode it using UTF-8: 0xE2 0xAC 0xA6

  3. You open the stream in a tool that's configured to use the single-byte encoding that's widely used in your area: Windows-1252

  4. You look up the individual bytes of the UTF-8 character in the character table of the single-byte encoding:

    • 0xE2 -> â
    • 0xAC -> ¬
    • 0xA6 -> ¦
  5. You encode the resulting characters in UTF-8:

    • â = 'LATIN SMALL LETTER A WITH CIRCUMFLEX' (U+00E2) = 0xC3 0xA2
    • ¬ = NOT SIGN' (U+00AC) = 0xC2 0xAC
    • ¦ = 'BROKEN BAR' (U+00A6) = 0xC2 0xA6

Thus you've transformed the UTF-8 stream 0xE2 0xAC 0xA6 () into the also UTF-8 stream 0xC3 0xA2 0xC2 0xAC 0xC2 0xA6 (⬦).

To undo this you need to reverse the steps. That's straightforward if you know what proxy encoding was used (Windows-1252 in my example):

$mojibake = "\xC3\xA2\xC2\xAC\xC2\xA6";
$proxy = 'Windows-1252';
var_dump($mojibake, bin2hex($mojibake));
$original = mb_convert_encoding($mojibake, $proxy, 'UTF-8');
var_dump($original, bin2hex($original));
string(6) "⬦"
string(12) "c3a2c2acc2a6"
string(3) "⬦"
string(6) "e2aca6"

But it's tricky if you don't. I guess you can:

  1. Compile a dictionary of the different byte sequences you get in the different single-byte encodings and then use some kind of bayesian inference to figure out the most likely encoding. (I can't really help you with this.)

  2. Try the most likely encodings and visually inspect the output to determine which is correct:

    // Source code saved as UTF-8
    $mojibake = "Z…Z";
    foreach (mb_list_encodings() as $proxy) {
        $original = mb_convert_encoding($mojibake, $proxy, 'UTF-8');
        echo $proxy, ': ', $original, PHP_EOL;
    }
    
  3. If (as in your case) you know what the original text is and you're kind of sure that you don't have mixed encodings, do as #2 but trying all the encodings PHP supports:

    // Source code saved as UTF-8
    $mojibake = 'Z…Z';
    $expected = 'Z⬦Z';
    foreach (mb_list_encodings() as $proxy) {
        $current = @mb_convert_encoding($mojibake, $proxy, 'UTF-8');
        if ($current === $expected) {
            echo "$proxy: match\n";
        }
    }
    

    (This prints wchar: match; not really sure what that means.)

🌐
Code Beautify
codebeautify.org › utf8-converter
UTF 8 Converter Online tool to encode UTF8 text
UTF 8 Converter is Transformer Online Utility. Load form URL, Download, Save and Share.