我正在製作一個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