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.
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 olleHExample 2: Numeric String
$str = "12345";
$result = strrev($str);
echo $result; // Output: 54321Example 3: Special Characters
$str = "Hello, World!";
$result = strrev($str);
echo $result; // Output: !dlroW ,olleHExample 4: Multi-line Text
$str = "Hello
World";
$result = strrev($str);
echo $result; // Output:
// dlroW
// olleHApplication 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.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
php Courses
php中文网's platform for the latest courses and technical articles, helping PHP learners advance quickly.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
