Is there any way to simply convert text to HTML ASCII code? Here's what I currently have, but I think it could be done much easier.
This works, but the code's a bit confusing...
PHP:
function strtoascii($text)
{
$final_text = '';
$alpha = array(64 => "@",
"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z",
"[","\\","]","^","_","`",
"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z");
$alpha['46'] = ".";
for ($i=0;$i<10;$i++)
{
$alpha[$i+48] .= $i;
}
for ($i=0;$i<strlen($text);$i++)
{
$char = substr($text,$i,1);
$ascii = array_search($char,$alpha);
if ($ascii === false)
{
$ascii = $char;
}
$final_text .= "&#".$ascii.";";
}
return $final_text;
}
This works, but the code's a bit confusing...
Last edited:




