Created
July 30, 2014 14:53
-
-
Save garvinhicking/31226088869ffba3bcc2 to your computer and use it in GitHub Desktop.
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
function mystify(&$handler, $newhandler) { | |
$regex = '@(\w+)="([^"]+)"@imsU'; | |
preg_match($regex, $newhandler, $newhandlerpart); | |
$new = array(); | |
$has_handle = false; | |
if (preg_match_all($regex, $handler, $handlerparts)) { | |
foreach($handlerparts[1] AS $idx => $handle) { | |
if ($handle == $newhandlerpart[1]) { | |
$has_handle = true; | |
$new[$newhandlerpart[1]] = $handlerparts[2][$idx] . ' ' . $newhandlerpart[2]; | |
} else { | |
$new[$handle] = $handlerparts[2][$idx]; | |
} | |
} | |
} | |
if (!$has_handle) { | |
$new[$newhandlerpart[1]] = $newhandlerpart[2]; | |
} | |
$handler = ''; | |
foreach($new AS $hkey => $hval) { | |
$handler .= $hkey .= '="' . $hval . '" '; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment