Logical input. The string holds Hebrew in typing/storage order.
Convert.hebrev() rearranges for visual (non-BiDi) display.
Terminal note. Your console may still render RTL visually—compare in a strict LTR plain-text viewer.
Encoding. Historically aimed at single-byte Hebrew; for the web, prefer dir="rtl".
Example 3 — Prefer HTML RTL for Web Pages
On modern sites, let the browser handle BiDi. Escape output with htmlspecialchars().
PHP
<?php
$text = "שלום";
// Better for HTML than hebrev():
echo '<p lang="he" dir="rtl">'
. htmlspecialchars($text, ENT_QUOTES, "UTF-8")
. "</p>";
Output
<p lang="he" dir="rtl">שלום</p>
How It Works
Keep logical order. Do not rearrange with hebrev() for HTML.
Mark direction.dir="rtl" and lang="he" tell the browser to render RTL.
Escape.htmlspecialchars() keeps the page safe from HTML injection.
When hebrev fits. Use it for plain-text / legacy channels without BiDi.
Frequently Asked Questions
hebrev() converts logical Hebrew text into visual Hebrew text. Logical order is how Hebrew is stored when typed; visual order rearranges characters for systems that do not support bidirectional (BiDi) rendering—such as plain-text email or old terminals.
string hebrev(string $string, int $max_chars_per_line = 0). The first argument is the input string. The optional second argument sets a maximum line width; when greater than 0, PHP wraps the visual text and tries not to break words.
Logical order follows typing and Unicode storage (used by modern browsers with dir="rtl"). Visual order rearranges characters for left-to-right-only displays. hebrev() produces visual order for legacy plain-text contexts.
Usually no. Prefer HTML lang="he" and dir="rtl" (or CSS direction: rtl) so the browser handles BiDi. Reserve hebrev() for plain-text output where BiDi is unavailable.
hebrev() returns one visual string. hebrevc() also converts newlines to <br>\ for HTML. hebrevc() was removed in PHP 8—use nl2br(hebrev($text)) if you still need that behavior.