Skip to content

Instantly share code, notes, and snippets.

@nmicht
Created August 11, 2017 02:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nmicht/8b6f8ad3e86d3f4ba64eece3d72c20ee to your computer and use it in GitHub Desktop.
Save nmicht/8b6f8ad3e86d3f4ba64eece3d72c20ee to your computer and use it in GitHub Desktop.
Reverse all the content wrapped by parenthesis
<?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