In this tutorial, you shall learn how to reverse a string in PHP using strrev() function, with examples.

PHP String Reverse

To reverse a string in PHP, you can use strrev() function. Pass the string as argument to strrev() and the function returns a new string that is formed by reversing the original string.

Examples

ADVERTISEMENT

1. Reverse a string

In the following example, we will take a PHP String literal and reverse it using strrev() function.

PHP Program

<?php
$str = 'Welcome to TutorialKart';
$reverse = strrev($str);
echo $reverse;
?>

Program Output

Python String Reverse

Conclusion

In this PHP Tutorial, we learned how to reverse a string using strrev() function.