Skip to content

Instantly share code, notes, and snippets.

@gitllermopalafox
Last active April 4, 2018 21:45
Show Gist options
  • Select an option

  • Save gitllermopalafox/0a8b60eaafede6af0b75 to your computer and use it in GitHub Desktop.

Select an option

Save gitllermopalafox/0a8b60eaafede6af0b75 to your computer and use it in GitHub Desktop.
Para resolver los errores con la función preg_replace() en symfony 1.4
/*
Para resolver los errores con la función preg_replace() en symfony 1.4:
Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead...
http://stackoverflow.com/questions/18077276/symfony-1-4-using-deprecated-functions-in-php-5-5/18086043#18086043
*/
/*
In myproject/lib/vendor/symfony/lib/response/sfWebResponse.class.php on line 409, I have now (commented code is original Symfony code):
*/
protected function normalizeHeaderName($name)
{
// return preg_replace('/\-(.)/e', "'-'.strtoupper('\\1')", strtr(ucfirst(strtolower($name)), '_', '-'));
return preg_replace_callback(
'/\-(.)/',
function ($matches) {
return '-'.strtoupper($matches[1]);
},
strtr(ucfirst(strtolower($name)), '_', '-')
);
}
/*
And in myproject/lib/vendor/symfony/lib/util/sfToolkit.class.php on line 362 we get:
*/
public static function pregtr($search, $replacePairs)
{
// return preg_replace(array_keys($replacePairs), array_values($replacePairs), $search);
foreach($replacePairs as $pattern => $replacement)
$search = preg_replace_callback(
$pattern,
function ($matches) use ($replacement){
if(array_key_exists(1, $matches)){ $replacement = str_replace("\\1", $matches[1], $replacement);}
if(array_key_exists(2, $matches)){ $replacement = str_replace("\\2", $matches[2], $replacement);}
return $replacement;
},
$search
);
return $search;
}
@dieggob

dieggob commented Apr 7, 2017

Copy link
Copy Markdown

Hello, Hey friend, Can I do a question?
Where should I put this code for the correct the error?
Thank you so much your help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment