Content · Programming · PHP

PHP Locale::isRightToLeft() Method: Usage and Examples

Learn how to determine whether a locale commonly uses right-to-left writing in PHP with syntax, clear code examples, practical use, and common mistakes.

1 views Published Oct 16, 2026 Updated Oct 16, 2026

When working with PHP, you may need to determine whether a locale commonly uses right-to-left writing. This guide explains the operation, shows what its arguments mean, and uses three separate examples to make the result easier to understand.

Locale::isRightToLeft: PHP 8.5 introduced this method. ICU determines direction from the dominant script of the locale.

What Is Locale::isRightToLeft in PHP?

Determine whether a locale commonly uses right-to-left writing. PHP 8.5 introduced this method. ICU determines direction from the dominant script of the locale.

Syntax:

Locale::isRightToLeft(string $locale = ""): bool

Parameters and return value: The signature above identifies the arguments and return type where the API has a single call. For topic guides, follow the sequence of calls in the examples. Always distinguish a returned value from an object or variable modified by reference.

Important: Requires PHP 8.5 and intl. The dominant script is not a guarantee that every piece of text within a page uses the same direction.

Example 1: Basic Usage

This example introduces the operation with a short and predictable input.

<?php

var_dump(Locale::isRightToLeft("ar"));

The code focuses on the main operation. PHP 8.5 introduced this method. ICU determines direction from the dominant script of the locale.

Example 2: Another Case

Now compare a different input, locale, date, or option to see another part of the behavior.

<?php

var_dump(Locale::isRightToLeft("en_US"));

What changes? Requires PHP 8.5 and intl. The dominant script is not a guarantee that every piece of text within a page uses the same direction.

Practical Example: Applying It in an Application

Use the following separate example as a starting point for a small application task. Check any extension or environment requirements below before running it.

<?php

$selectedLocale = "he_IL";
$textDirection = Locale::isRightToLeft($selectedLocale) ? "rtl" : "ltr";
echo "Text direction: " . $textDirection;

The practical example demonstrates how to apply this operation to multiple values, a reusable task, or a validated input. PHP 8.5 introduced this method. ICU determines direction from the dominant script of the locale.

Important Behavior and Edge Cases

  • Core behavior: PHP 8.5 introduced this method. ICU determines direction from the dominant script of the locale.
  • Inputs and results: Requires PHP 8.5 and intl. The dominant script is not a guarantee that every piece of text within a page uses the same direction.
  • Alternatives: For layout, the HTML dir attribute controls text direction, while Locale identifies language preferences.
  • Compatibility: The intl extension is required.
  • Compatibility: This method was introduced in PHP 8.5.

Comparison With Related Functions

Function or ApproachWhen to Use It
Locale::isRightToLeftDetermine whether a locale commonly uses right-to-left writing.
Related PHP approachFor layout, the HTML dir attribute controls text direction, while Locale identifies language preferences.

Common Beginner Mistakes

MistakeCorrect Approach
Using an incorrect input or optionRequires PHP 8.5 and intl. The dominant script is not a guarantee that every piece of text within a page uses the same direction.
Confusing this API with a related operationFor layout, the HTML dir attribute controls text direction, while Locale identifies language preferences.
Assuming output is identical across environmentsCheck return values and required extensions or versions. The intl extension is required. This method was introduced in PHP 8.5.

Key Takeaways

  • Locale::isRightToLeft helps you determine whether a locale commonly uses right-to-left writing.
  • PHP 8.5 introduced this method. ICU determines direction from the dominant script of the locale.
  • Requires PHP 8.5 and intl. The dominant script is not a guarantee that every piece of text within a page uses the same direction.

Use Locale::isRightToLeft when you need to determine whether a locale commonly uses right-to-left writing. Start with the first example, compare the second, and adapt the practical example to your inputs. Confirm the return value and environment requirements before adding it to production code.

Share this resourceSend this page to someone who may find it useful.