Master PHP’s strrev(): Syntax, Examples, and Real-World Uses

This guide introduces PHP’s strrev() function, covering its syntax, parameters, return value, and multiple practical examples—from basic string reversal to handling numbers, special characters, and multi-line text—while also highlighting common use cases such as palindrome checks and simple data obfuscation.

php Courses
php Courses
php Courses
Master PHP’s strrev(): Syntax, Examples, and Real-World Uses

In PHP, the strrev() function is a handy string function that reverses a given string. This article explains its syntax, parameters, return value, and provides several practical examples.

strrev() Syntax and Parameters

The function is defined as: string strrev ( string $string ) The $string parameter is the string to be reversed.

Return Value

strrev()

returns the reversed string.

Examples

Example 1: Basic Usage

$str = "Hello World";
$result = strrev($str);
echo $result; // Output: dlroW olleH

Example 2: Numeric String

$str = "12345";
$result = strrev($str);
echo $result; // Output: 54321

Example 3: Special Characters

$str = "Hello, World!";
$result = strrev($str);
echo $result; // Output: !dlroW ,olleH

Example 4: Multi-line Text

$str = "Hello
World";
$result = strrev($str);
echo $result; // Output:
 // dlroW
 // olleH

Application Scenarios

Reversing strings for special formatting needs.

Checking palindrome strings by comparing the original with its reversed version.

Simple data obfuscation in custom encryption routines.

General string manipulation tool within larger processing pipelines.

Conclusion

This article detailed the usage and examples of strrev(), helping readers improve their string handling capabilities in PHP development.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

PHPString Manipulationstrrev
php Courses
Written by

php Courses

php中文网's platform for the latest courses and technical articles, helping PHP learners advance quickly.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.