php - Parse error: syntax error, unexpected T_FUNCTION line 10? -


what wrong code? ran code on test server , code worked when upload production server

parse error: syntax error, unexpected t_function in /hermes/bosweb/web013/b130/ipg.acrsflcom/darayngedbeats/gentest.php on line 10 

here code

$old = "http://darayngedbeats1.s3.amazonaws.com    /mp3/crazymonsta2.mp3?awsaccesskeyid=akiajxa36esclqhcb54q&expires=1297279906& signature=hd36zqe8yetiw6jpwkmcciptits%3d"; //enter key needs converted $search =  array(":","?","=","&","%"); $replace = array("%3a","%3f","%3d","%26","%25");  function search_replace($s,$r,$sql) { $e = '/('.implode('|',array_map('preg_quote', $s)).')/';   $r = array_combine($s,$r);   return preg_replace_callback($e, function($v) use ($s,$r) { return $r[$v[1]];  },$sql); }  echo "<br><br>"; $new = search_replace($search,$replace,$old); echo $new;  ?> 

the error caused

return preg_replace_callback($e, function($v) use ($s,$r) { return $r[$v[1]];  },$sql); 

chances you're using php 5.2 or earlier, doesn't support closures. can find out version of php you're using phpinfo().

you'll either need upgrade php 5.3+, or use create_function, or write static function , pass callback.

here's example of last option, using simple class store state of $r:

class my_callback {   public function __construct($s, $r) {     $this->s = $s; $this->r = $r;   }     function callback($v) { return $this->r[$v[1]]; } }  function search_replace($s,$r,$sql) {   $e = '/('.implode('|',array_map('preg_quote', $s)).')/';   $r = array_combine($s,$r);   $c = new my_callback($s, $r);   return preg_replace_callback($e, array($c, 'callback'), $sql); } 

Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -