I'm making a PHP script to reverse the text within an HTML document to handle badly converted Hebrew PDFs. (sigh :))
Everything works, however the script has a very strange output. Only SOME of the characters, instead of staying Hebrew letters, turn into blank characters (those black diamonds with question marks).
I tried some solution I could find on SO and beyond but nothing changed. Perhaps you can enlighten me?
You can check the script in action here: pilau.phpnet.us/html_invert.php, and this is the entire source code:
<!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>