What is PHP hebrev() Function?
If you want to display Hebrew text in right to left order in an environment (ex. web browser) where texts are displayed logically from left to right, use PHP hebrev() function.
Syntax:
hebrev(string, max_chars_per_line)
Parameters:
The Function has 1 required parameter and 1 optional parameter-
string (Required): It specifies a Hebrew string that is in its logical representation (left to right). Check example 1.
max_chars_per_line (Optional): It specifies maximum number of characters per line. The default is 0 (no line breaking). The function wraps the string without breaking words. Check example 2.
Return Values:
The function returns the converted visual string.
Examples:
Example 1:
<?php
$logical_text = "שלום עולם - מתל אביב, ישראל.";
$visual_text = hebrev($logical_text);
echo "Logical Text: $logical_text <br />";
echo "Visual Text: $visual_text";
?>
Output:
Logical Text: שלום עולם - מתל אביב, ישראל.
Visual Text: .שלום עולם - מתל אביב, ישראל
Example 2:
<?php
$logical_text = "שלום עולם זה טקסט בעברית";
$visual_text = nl2br(hebrev($logical_text, 4));
echo "Logical Text: $logical_text <br />";
echo "Visual Text: $visual_text";
?>
Output:
Logical Text: שלום עולם זה טקסט בעברית
Visual Text: �יתעב�ב
�סטט�
זה
�לםע�
�וםש�
PHP Version Support:
PHP 4, PHP 5, PHP 7, PHP 8
Summary: PHP hebrev() Function
hevrev() function is one of the built-in string functions. Use this function to display Hebrew text from right to left in your web browsers.