i have function parameter pass.
for example:
$this->avatar->getavatar('size=s/user=synergy'); now want explode string @ "/" , key example "user" , value "synergy". , every explode.
here function:
public function getavatar($params) { $this->params = explode('/', $params); if(strpos($this->params, 'size=') !== false) { $this->size = // how value after "=" ?? } if(strpos($this->params, 'user=') !== false) { $this->user = // how value after "=" ?? } }
try this:
<?php $var = 'size=s3435/user=synergy'; $temp = explode('/', $var); //fetch size $pos = strpos($temp[0], '='); echo substr($temp[0], 0, $pos); //key echo substr($temp[0], $pos+1); //value //fetch user $pos = strpos($temp[1], '='); echo substr($temp[1], 0, $pos); echo substr($temp[1], $pos+1); ?> avail @ https://ideone.com/bxqook
note: use loop if have many key-value pairs separated /
Comments
Post a Comment