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.
Fundamentals
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.
Foundation
📝 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.
Cheat Sheet
⚡ 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
Hands-On
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.
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().
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.
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.
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().
Applications
🚀 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).
Important
📝 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.
Wrap Up
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.
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
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about hebrevc()
Essential points for legacy code and PHP 8 migration.
5
Core concepts
🔄01
hebrev + <br>
Visual + line breaks.
Purpose
📝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.