Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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