PHP hebrevc() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
String

Definition

In PHP, hebrevc() is like hebrev(), but it also converts newlines to <br>\n for HTML display.

The string is required. An optional max line length can wrap the text during conversion.

Syntax

Call hebrevc on the Hebrew string. Start with this line.

PHP
$html = hebrevc($logical);
CallWhat it does
hebrevc($logical)Visual Hebrew with HTML line breaks.
hebrev($logical)Visual Hebrew without HTML breaks.

Deprecated/legacy in many modern stacks. Prefer Unicode bidi rendering.

Library declarations
PHP
hebrevc(string $string, int $max_chars_per_line = 0): string

Parameters

ParameterDescription
stringRequired. Logical Hebrew text.
max_chars_per_lineOptional. Wrap width. Default 0 means no wrapping.

Return Value

Return ValueDescription
stringVisual Hebrew text with HTML line breaks.

PHP Examples

Example 1 — hebrev() vs hebrevc() (PHP ≤ 7.3)

Same input: only hebrevc() injects <br>. See also hebrev().

PHP
<?php
// Requires PHP 7.3 or earlier (hebrevc removed in PHP 8)
$text = "שלום\nעולם";

$plain  = hebrev($text);
$withBr = hebrevc($text);

echo "hebrev()  has <br>: " . (strpos($plain,  '<br>') !== false ? "yes\n" : "no\n");
echo "hebrevc() has <br>: " . (strpos($withBr, '<br>') !== false ? "yes\n" : "no\n");
?>

How It Works

  1. Shared job. Both reorder Hebrew for visual / legacy displays.
  2. Extra step. hebrevc() turns newlines into <br>\n.
  3. Detect the difference. Search the result for the <br> tag.
  4. Version note. This file will fatally error on PHP 8 if you call hebrevc().

Example 2 — PHP 8+ Replacement

Rebuild the old behavior with hebrev() and nl2br().

PHP
<?php
$text = "שורה א\nשורה ב";

// Old (PHP 7.3 and earlier):
// $out = hebrevc($text);

// PHP 8+ equivalent:
$out = nl2br(hebrev($text), false);

echo "Contains <br>: " . (strpos($out, '<br') !== false ? "yes\n" : "no\n");
?>

How It Works

  1. Reorder first. hebrev() still exists in PHP 8.
  2. Then insert breaks. nl2br() converts newlines to HTML breaks.
  3. false argument. Prefer <br> over XHTML <br /> when matching old output.
  4. Drop-in migration. Search/replace hebrevc( with this pattern during upgrades.

Example 3 — Modern HTML (Recommended)

For new pages, let the browser handle RTL. Escape with htmlspecialchars().

PHP
<?php
$paragraphs = "שורה ראשונה\nשורה שנייה";

$html = '<div dir="rtl" lang="he">' .
        nl2br(htmlspecialchars($paragraphs, ENT_QUOTES, 'UTF-8'), false) .
        '</div>';

echo "Uses dir=rtl + htmlspecialchars + nl2br\n";
?>

How It Works

  1. Set direction. dir="rtl" and lang="he" tell the browser this is Hebrew.
  2. Escape first. htmlspecialchars() prevents XSS from user text.
  3. Then line breaks. nl2br() turns \n into visible HTML breaks.
  4. Skip visual conversion. Modern BiDi does not need hebrev()/hebrevc().

Frequently Asked Questions

hebrevc() converts logical Hebrew text to visual text—just like hebrev()—and also converts each newline character (\ ) to the literal string <br> followed by a newline (<br>\ ). That made it convenient for legacy HTML snippets rendered without CSS white-space handling.
string hebrevc(string $hebrew_text, int $max_chars_per_line = 0). Parameters match hebrev(): Hebrew input string and an optional maximum characters per line for wrapping.
hebrev() only reorders Hebrew characters for visual display. hebrevc() does the same reordering and additionally inserts <br> before each line break—useful when echoing preformatted Hebrew into old HTML pages.
No. hebrevc() was deprecated in PHP 7.4.0 and removed in PHP 8.0.0. On PHP 8+, use nl2br(hebrev($text)) if you still need the same behavior, or prefer modern HTML with dir="rtl" and nl2br(htmlspecialchars($text)).
Replace hebrevc($text) with nl2br(hebrev($text)). hebrev() itself still exists in PHP 8. For new web projects, skip both and render Hebrew with dir="rtl", lang="he", and htmlspecialchars().

Next: hex2bin()

Decode hexadecimal strings into binary data.

hex2bin() tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

9 people found this page helpful