Skip to content

Instantly share code, notes, and snippets.

@pkruithof
Created June 22, 2011 13:07
Show Gist options
  • Save pkruithof/1040053 to your computer and use it in GitHub Desktop.
Save pkruithof/1040053 to your computer and use it in GitHub Desktop.
UTF-8 to ASCII
<?php
$str = $_REQUEST['body'];
for ($i = 0; $i < strlen($str); $i++) {
$byte = $str[$i];
if (ord($byte) > 127) {
$output .= "\\x" . bin2hex($byte);
} else {
$output .= addcslashes(str_replace("\r", "", $byte), "\0..\37");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment