Domanda

code below gives a deprecation warning after upgrading to PHP 5.5+

$sentence=preg_replace('/~([^<>]{1,})~/e', "'<span class=\"helpstart\">'.UTF8_strtoupper('\\1').'</span>'", $sentence);

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in ..

How can I replace the code with preg_replace_callback()?

È stato utile?

Soluzione

$sentence=preg_replace('/~([^<>]{1,})~/', function($match) {return "<span class=\"helpstart\">".UTF8_strtoupper($match)."</span>"; } , $sentence);

as per http://www.php.net/manual/en/function.preg-replace-callback.php

Altri suggerimenti

$sentence=preg_replace_callback('/~([^<>]{1,})~/', function($match) {return "<span class=\"helpstart\">".UTF8_strtoupper($match[1])."</span>"; } , $sentence);

The first answer was an error on the function.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top