PHP hebrevc() Function

Beginner
⏱️ 7 min read
📚 Updated: Jul 2026
🎯 5 Examples
String Functions

What You’ll Learn

The hebrevc() function is like hebrev() plus automatic <br> insertion at line breaks—a legacy helper for old HTML output. It was removed in PHP 8.0; this tutorial explains how it worked and what to use today.

01

hebrev + <br>

Visual Hebrew + breaks.

02

Newline Map

\n<br>\n.

03

vs hebrev()

Only diff is <br>.

04

Deprecated

Removed in PHP 8.0.

05

PHP 8 Fix

nl2br(hebrev()).

06

Modern HTML

dir="rtl" + CSS.

Definition and Usage

In PHP, hebrevc() converts logical Hebrew text to visual Hebrew text (identical to hebrev()) and transforms each newline into <br> followed by a newline. That let developers echo multi-line Hebrew into HTML without wrapping content in <pre> tags.

⚠️
PHP 8+ Notice

hebrevc() was deprecated in PHP 7.4 and removed in PHP 8.0. If you maintain legacy code, replace hebrevc($text) with nl2br(hebrev($text)). For new projects, use dir="rtl", lang="he", and htmlspecialchars() instead.

📝 Syntax

The function mirrors hebrev() with the same optional line-width parameter:

PHP
string hebrevc(
    string $hebrew_text,
    int $max_chars_per_line = 0
)

Parameters

  • $hebrew_text — Hebrew input string in logical order.
  • $max_chars_per_line — optional maximum characters per line. 0 means no wrapping; a positive value wraps visual output and tries not to break words.

Return Value

Returns a visual-order Hebrew string with <br> tags inserted before each original newline.

⚡ Quick Reference

Legacy (PHP < 8)
hebrevc($hebrew)

Visual + <br> tags

PHP 8+ replacement
nl2br(hebrev($hebrew))

Same idea today

vs hebrev()
hebrev($text)

No <br> conversion

Modern web
dir="rtl" lang="he"

Preferred approach

Examples Gallery

Examples marked PHP 7.3 and earlier use hebrevc() directly. On PHP 8+, run the replacement patterns instead. All examples assume UTF-8 Hebrew strings.

📚 Getting Started

Single-line Hebrew behaves like hebrev()—no newlines means no <br> tags.

Example 1 — Single-Line Hebrew (PHP 7.3 and earlier)

Without newline characters, output matches hebrev() for the same input.

PHP
<?php
$hebrew = "שלום, עולם!";
$formatted = hebrevc($hebrew);

echo "Original:  $hebrew\n";
echo "Formatted: $formatted\n";
echo "Has <br>: " . (str_contains($formatted, '<br>') ? "yes\n" : "no\n");
?>

How It Works

With no \n in the input, hebrevc() only performs the visual Hebrew conversion—the same result as calling hebrev() alone.

Example 2 — Multiline Text Inserts <br> Tags

This is the key difference from hebrev(): each line break becomes <br> in the returned string.

PHP
<?php
$text = "שורה ראשונה\nשורה שנייה\nשורה שלישית";
$formatted = hebrevc($text);

echo substr_count($formatted, '<br>') . " <br> tag(s)\n";
echo "---\n";
echo $formatted;
?>

How It Works

Two internal newlines produce two <br> insertions (before the second and third lines). The exact visual Hebrew order depends on PHP’s conversion rules; the <br> count is the reliable difference to watch for.

📈 Practical Patterns

Compare functions, migrate to PHP 8, and use modern HTML.

Example 3 — hebrev() vs hebrevc() Side by Side

See exactly what hebrevc() adds on top of hebrev().

PHP
<?php
$text = "שלום\nעולם";

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

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

How It Works

Both functions reorder Hebrew visually. Only hebrevc() injects HTML line-break tags at newline positions—making it suitable for legacy pages that echoed raw strings into the document body.

Example 4 — PHP 8+ Replacement with nl2br(hebrev())

Because hebrevc() was removed, rebuild its behavior from two still-supported functions.

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

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

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

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

How It Works

hebrev() handles visual reordering; nl2br() converts newlines to <br> tags. Together they replicate what hebrevc() did in one call on older PHP versions.

Example 5 — Modern HTML (Recommended for New Projects)

Skip legacy conversion entirely—let the browser handle direction and line breaks safely.

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

// Safe HTML output — no hebrevc() needed
$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

Modern browsers render logical-order UTF-8 Hebrew correctly when you set text direction and language. Escape user content with htmlspecialchars(), convert newlines with nl2br(), and avoid pre-converting character order with hebrev() or hebrevc().

🚀 Common Use Cases

  • Legacy PHP 7 maintenance — understand old code that still calls hebrevc().
  • Migration to PHP 8 — replace with nl2br(hebrev($text)) during upgrades.
  • Multi-line Hebrew in old HTML — pages that echoed strings directly without <pre> or CSS.
  • Interview / certification prep — know deprecated functions and their replacements.
  • Contrasting legacy vs modern i18n — compare with dir="rtl" best practices.

🧠 How hebrevc() Works

1

Logical Hebrew input

You pass a UTF-8 string—optionally containing \n line breaks—in logical storage order.

Input
2

Visual reorder (hebrev step)

PHP reorders Hebrew characters for left-to-right-only display, same as hebrev().

Transform
3

<br> at each newline

Every \n becomes the literal sequence <br> followed by a newline character.

HTML breaks
=

HTML-ready visual string

Ready to echo into legacy HTML pages (PHP 7.3 and earlier only).

📝 Notes

  • Deprecated in PHP 7.4.0; removed in PHP 8.0.0.
  • PHP 8+ replacement: nl2br(hebrev($text)) (when visual conversion is still required).
  • Hebrew only—not for Arabic or other RTL scripts.
  • Inserts raw <br> tags; do not run the result through htmlspecialchars() afterward or the tags will display as text.
  • For new web apps, prefer dir="rtl", lang="he", and escaped logical-order UTF-8 text.

Conclusion

The hebrevc() function combined visual Hebrew conversion with HTML line-break insertion—a convenience for legacy PHP applications. It is no longer available in PHP 8, but understanding it helps when reading or migrating older codebases.

Replace it with nl2br(hebrev($text)) during upgrades, or better yet, adopt modern RTL HTML patterns and drop visual-order conversion entirely for web output.

💡 Best Practices

✅ Do

  • Replace hebrevc() with nl2br(hebrev()) on PHP 8+
  • Use UTF-8 for all Hebrew source strings
  • Prefer dir="rtl" and lang="he" for new HTML
  • Escape user content with htmlspecialchars() before output
  • Document deprecated calls when maintaining legacy projects

❌ Don’t

  • Call hebrevc() on PHP 8+ (function does not exist)
  • Double-escape strings that already contain <br> tags
  • Assume hebrevc() replaces proper RTL CSS
  • Use it for Arabic or mixed-script BiDi without testing
  • Introduce hebrevc() into new PHP 8 projects

Key Takeaways

Knowledge Unlocked

Five things to remember about hebrevc()

Essential points for legacy code and PHP 8 migration.

5
Core concepts
📝 02

Same Parameters

As hebrev().

Syntax
03

Removed in PHP 8

Deprecated in 7.4.

Status
🛠 04

PHP 8 Fix

nl2br(hebrev()).

Migration
🎨 05

Modern RTL HTML

dir="rtl" preferred.

Today

❓ Frequently Asked Questions

hebrevc() converts logical Hebrew text to visual text—just like hebrev()—and also converts each newline character (\n) to the literal string <br> followed by a newline (<br>\n). 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().
No. Like hebrev(), hebrevc() is designed for Hebrew only. Other right-to-left scripts need Unicode BiDi support in the browser or application—not these legacy PHP functions.

Explore More PHP String Functions

Continue with hex2bin(), html_entity_decode(), and the rest of the string function reference.

Next: hex2bin() →

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.

6 people found this page helpful