acctman Posted September 2, 2015 Share Posted September 2, 2015 can someone help me change this to preg_replace_callback. i'm receiving the following error Warning: preg_replace_callback(): Requires argument 2, '@constant("\1")', to be a valid callback in //load current language foreach ($langs as $key => $value) if ($value['l_code'] == lang) break; $f = fopen('languages/'.$langs[$key]['l_file'],'r') or die('Cannot open language file '.$langs[$key]['l_file']); while (!feof($f)) { $s = chop(fgets($f,4096)); if ($s{0} == '#') continue; list($key,$value) = explode('=',$s,2); $value = preg_replace('/<%(.*)%>/sUe', '@constant("\\1")', $value); $def[$key] = $value; } fclose($f); Quote Link to comment Share on other sites More sharing options...
Solution requinix Posted September 2, 2015 Solution Share Posted September 2, 2015 (edited) After you change the function to be preg_replace_callback, you also have to change the second argument to be a function and not a mere string. The simplest way is to use an anonymous function like function($matches) { // ... } $matches will be an array just like how preg_match() works, what with [0] being the full string and [1] being a captured group. Inside this function you call constant() and return whatever you want the replacement to be. Give that a shot. If you still have problems, post the code you tried. Edited September 2, 2015 by requinix Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.