Skip to content

Instantly share code, notes, and snippets.

@nicolish
Created December 22, 2008 16:22
Show Gist options
  • Save nicolish/39036 to your computer and use it in GitHub Desktop.
Save nicolish/39036 to your computer and use it in GitHub Desktop.
<?php
function process($str, $ldelim, $rdelim){
$begin = strpos($str, $ldelim);
$end = strpos($str, $rdelim, $begin + strlen($ldelim));
if(false === $begin){
return strtoupper($str);
}
if(false === $end){
return strtoupper(substr($str, 0, $begin)) . $ldelim
. strtolower(substr($str, $begin + strlen($ldelim)));
}
$return = strtoupper(substr($str, 0, $begin)) . $ldelim
. strtolower(substr($str, $begin + strlen($ldelim), $end - $begin - strlen($ldelim)))
. $rdelim . process(substr($str, $end + strlen($rdelim)), $ldelim, $rdelim);
return $return;
}
$input_str = 'abcdEFG
<test>
ABCDEFG
</test>
hiJKLmn';
echo process($input_str, '<test>', '</test>');
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment