Created
August 11, 2017 02:45
-
-
Save nmicht/8b6f8ad3e86d3f4ba64eece3d72c20ee to your computer and use it in GitHub Desktop.
Reverse all the content wrapped by parenthesis
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$string = '12(345)6(78)8(012(34(56)7))0123'; | |
$regex = '/(\(\w+\))/'; | |
$result = $string; | |
while( strpos($resultado,'(') !== false) { | |
$result = preg_replace_callback($regex, function($matches) { | |
return strrev(substr($matches[1],1,-1)); | |
}, $result); | |
} | |
echo 'Original: ',$string; | |
echo PHP_EOL; | |
echo 'Result: ',$resulta; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment