Subdomain Posts
PHP | 3 hours ago
PHP | 13 hours ago
PHP | 17 hours ago
Java | 2 days ago
PHP | 2 days ago
PHP | 2 days ago
HTML | 3 days ago
PHP | 4 days ago
Recent Posts
Java | 1 min ago
C++ | 2 min ago
None | 3 min ago
Lua | 4 min ago
None | 5 min ago
None | 5 min ago
None | 5 min ago
Java | 5 min ago
What is pastebin?
Pastebin is a website that hosts all your text & code on dedicated servers for easy sharing.
learn more...
Domain Reports
By Toby Inkster on the 29th of Jan 2009 04:32:40 AM
Download |
Raw |
Embed |
Report
<?php
function ordUTF8 ($c, $index = 0, &$bytes = null)
{
$bytes = 0;
if ($index >= $len)
return false;
if ($h <= 0x7F)
{
$bytes = 1;
return $h;
}
else if ($h < 0xC2)
return false;
else if ($h <= 0xDF && $index < $len - 1)
{
$bytes = 2;
return ($h & 0x1F
) << 6
| (ord($c{$index + 1
}) & 0x3F
);
}
else if ($h <= 0xEF && $index < $len - 2)
{
$bytes = 3;
return ($h & 0x0F
) << 12
| (ord($c{$index + 1
}) & 0x3F
) << 6
| (ord($c{$index + 2
}) & 0x3F
);
}
else if ($h <= 0xF4 && $index < $len - 3) {
$bytes = 4;
return ($h & 0x0F
) << 18
| (ord($c{$index + 1
}) & 0x3F
) << 12
| (ord($c{$index + 2
}) & 0x3F
) << 6
| (ord($c{$index + 3
}) & 0x3F
);
}
else
return false;
}
function xml_entities ($utf8_string, $style='#')
{
$return = '';
{
$char = mb_substr($utf8_string, 0, 1, 'UTF-8');
$ord = ordUTF8($char, 0, $bytes);
$utf8_string = substr($utf8_string, $bytes);
if ($ord == 34)
$return .= '"';
elseif ($ord == 38)
$return .= '&';
elseif ($ord == 60)
$return .= '<';
elseif ($ord == 62)
$return .= '>';
elseif ($ord == 9 || $ord == 10 || $ord == 13)
$return .= $char;
elseif ($style == '#' && ($ord < 32 || $ord > 127 || $ord == 39))
$return .= '&#'.$ord.';';
elseif ($style == '#x' && ($ord < 32 || $ord > 127 || $ord == 39))
$return .= '&#'.dechex($ord).';';
else
$return .= $char;
}
return $return;
}
# Testing...
print xml_entities("Pound is £ & euro is € & plus or minus is ±\n");
?>
Submit a correction or amendment below.
[ previous version ] | [ difference ] | Make A New Post