I want to create a string of non-standard characters in PHP, such as characters 128-255, and then encode said string as CP1252:
<?php
$cp1252 = '';
for ($i = 128; $i < 256; $i++) {
$hex = dechex($i);
$cp1252 .= "\x$hex";
}
echo $cp1252;
I knew this wouldn't work because the escape sequence is parsed before the variable is initialized (correct me if I'm wrong), so this serves as an example of what I'd like to do.
This is the final code I used to test the conversion of CP1252 to UTF-8:
<?php
$cp1252 = '';
for ($i = 128; $i < 256; $i++) {
$cp1252 .= chr($i);
}
echo iconv("CP1252", "UTF-8", $cp1252);
Use the chr()
function to convert a character code to a string:
for ($i = 128; $i < 256; $i++) {
$cp1252 .= chr($i);
}