Skip to content

Instantly share code, notes, and snippets.

@Langmans
Created November 12, 2015 09:21
Show Gist options
  • Save Langmans/9484e085b457896ac579 to your computer and use it in GitHub Desktop.
Save Langmans/9484e085b457896ac579 to your computer and use it in GitHub Desktop.
if you accidently forgot to disable magic quotes :)
<?php
// magic quotes fix.
$app->after(function (
\Symfony\Component\HttpFoundation\Request $request,
\Symfony\Component\HttpFoundation\Response $response
) {
$content_type = $response->headers->get('content-type');
if (strpos($content_type, 'text/html') === 0) {
$response->setContent(preg_replace_callback('@(?<attribute>[a-z0-9]+)=(\\\\(?<enclosure>["|\']))(?<value>[^"\']+)\2@i',
function ($matches) {
$vals = array_combine(array_map(function ($key) {
return "%$key%";
}, array_keys($matches)), $matches);
return strtr('%attribute%=%enclosure%%value%%enclosure%', $vals);
}, $response->getContent()));
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment