PHP String hebrev() Function



The PHP String hebrev() function is used to reverse the flow of Hebrew text from right to left. It also replaces new lines (\n) with <br>.

The functions hebrevc() and hebrev() can convert Hebrew logical text (in Windows encoding) to Hebrew visual text. Hebrew visual needs no particular right to left character support to function properly, making it ideal for displaying Hebrew text on the web.

Syntax

Here is the syntax of the PHP String hebrev() function −

string hebrev(string $string, int $max_chars_per_line = 0)

Parameters

Below are the parameters of the hebrev() function −

  • $string − It contains the information about a hebrew string input.

  • $max_chars_per_line − It contains the information about max number of characters per line that will be returned.

Return Value

The hebrev() function returns the visual string.

PHP Version

First introduced in core PHP 4, the hebrev() function continues to function easily in PHP 5, PHP 7, and PHP 8.

Example 1

First we will show you the basic example of the PHP String hebrev() function to convert a simple Hebrew sentence from logical to visual text.

<?php
   // "Hello World" in Hebrew
   $hebrew_text = " "; 
   $converted_text = hebrev($hebrew_text);
   
   echo $converted_text;
?>

Output

Here is the outcome of the following code −

 

Example 2

The hebrev() function reverses a string. The array $texts contains the English phrases. The loop goes over each sentence and reverses it with the help of hebrev(), and then prints it.

<?php
   // Array of Hebrew text
   $texts = [
       "Hello World",
       "Hey Friends",
       "How are you?",
       "What's up?"
   ];
   
   // Loop through each text and reverse it
   foreach ($texts as $text) {
      // Display the reversed text 
      echo hebrev($text) . "\n";  
   }
?> 

Output

This will generate the below output −

Hello World
Hey Friends
?How are you
?What's up

Example 3

Here is another example to show the usage of hebrev() function.

<?php   
   $myText = " hebrev -PHP";
   $visual_text = hebrev($myText);
    
   if ($myText === $visual_text) {
       echo "Text is currently in visual order: $visual_text";
   } else {
       echo "Text is changed to visual order: $visual_text";
   }
?> 

Output

This will produce the following output −

Text is currently in visual order:  hebrev -PHP
php_function_reference.htm
Advertisements