我正在制作一个PHP脚本来反转HTML文档中的文本以处理转换不良的希伯来PDF文件。 (叹息:))我为什么会得到乱码字符?
一切正常,但脚本有一个非常奇怪的输出。只有一些字符,而不是保留希伯来字母,变成空白字符(那些带问号的黑色钻石)。
我尝试了一些解决方案,我可以找到SO和超越,但没有任何改变。也许你可以启发我?
您可以在这里的行动检查脚本:pilau.phpnet.us/html_invert.php,这是整个源代码:
<!DOCTYPE html>
<html lang="he-IL">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<form action="html_invert.php" method="post" enctype="application/x-www-form-urlencoded">
<textarea id="html_code" name="html_code" rows="30" cols="80"><?php
if (isset($_POST['html_code']))
{
function invert_string ($str) {
$new_str = '';
$i = strlen($str);
while ($i > 0) {
$new_str .= substr($str, --$i, 1);
}
return '>'.$new_str.'<';
}
echo htmlspecialchars(preg_replace('/>(\s*.*\s*)</imUue', 'invert_string("$1")', stripslashes($_POST['html_code'])));
}
else { echo 'paste your text here'; }
?></textarea>
<br />
<input type="submit" value="Process HTML" />
</form>
</body>
</html>
你想'mb_substr'和'mb_strlen'多字节安全。 – geoffspear 2012-04-20 15:05:12
另外,我不认为'stripslashes'是UTF安全的。 – Matthew 2012-04-20 15:05:43
我没有得到任何输出的链接.. – RyanS 2012-04-20 15:06:04