Skip to content

hebrev()

Note: The hebrev() function was deprecated in PHP 7.2 and completely removed in PHP 8.0. This documentation is provided for legacy code maintenance only. For modern web development, use HTML dir="rtl" or CSS direction: rtl to handle Hebrew text natively.

The hebrev() function simply reverses the order of characters in a Hebrew string to convert logical text to visual text for display on a web page. The syntax of the hebrev() function is as follows:

The PHP syntax of the hebrev()

php
string hebrev ( string $hebrew_text [, int $max_chars_per_line = 0 ] )

The function takes one required parameter, $hebrew_text, which is the Hebrew text to convert. The function also has an optional parameter, $max_chars_per_line, which specifies the maximum number of characters per line. If this parameter is not specified or set to 0, the function will use the default value of 80.

Here is an example of how to use the hebrev() function:

The example of PHP hebrev()

php
<?php
$hebrew_text = "כן, אני מדבר עברית";
echo hebrev($hebrew_text);
?>

In this example, we have a string variable $hebrew_text containing some Hebrew text. We use the hebrev() function to reverse the string so it displays correctly in left-to-right environments.

The output of this code will be:


console
תירבע רבדמ ינא ,ןכ

As you can see, the hebrev() function has reversed the character order to display the text in the correct visual format.

The hebrev() function can also be used to limit the number of characters per line in the output. Here is an example of how to use the hebrev() function with a limit of 40 characters per line:

How to use PHP hebrev()?

php
<?php
$hebrew_text = "כן, אני מדבר עברית";
echo hebrev($hebrew_text, 40);
?>

In this example, we have a string variable $hebrew_text containing some Hebrew text, and we use the hebrev() function with a limit of 40 characters per line.

The output of this code will be:


console
תירבע רבדמ ינא ,ןכ

As you can see, the hebrev() function has limited the number of characters per line to 40.

The hebrev() function is a legacy tool for converting Hebrew text to visual text. It can help maintain older codebases, but modern web pages should use HTML dir="rtl" or CSS direction: rtl for proper text direction and line wrapping. The related hebrevc() function, which also converts line breaks, is similarly removed in PHP 8.0; modern CSS handles line wrapping automatically. By understanding this function, you can better maintain legacy PHP applications.

We hope this article has been helpful in understanding the hebrev() function in PHP. If you have any questions or comments, please feel free to reach out to us.

Practice

What does the hebrev() function in PHP do?

Do you find this helpful?

Dual-run preview — compare with live Symfony routes.