Skip to content

Instantly share code, notes, and snippets.

@garvinhicking
Created July 30, 2014 14:53
Show Gist options
  • Save garvinhicking/31226088869ffba3bcc2 to your computer and use it in GitHub Desktop.
Save garvinhicking/31226088869ffba3bcc2 to your computer and use it in GitHub Desktop.
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