Home › Forums › Back End › use function variables like wordpress › Re: use function variables like wordpress
Well – is there any reason why you need to pass them like that firstly? Could you not just create an array and throw that in?
Because I am sure you know this already, that format is how your browser will POST and GET… I am not sure how WP are doing it in their code but I suppose you could explode the data into an array and use it that way…
$var = explode(‘&’, $string);
That would give you an array like
[0]=>title=home
[1]=>foo=bar
[2]=>this=that
Then you are atleast half way there – maybe then you could split them again…
EDIT:
Was just playing around with a double explode idea and thought I would check the PHP.net info on explode – and I found this awesome function
$array1 = explode("$del1", $array);
foreach($array1 as $key=>$value){
$array2 = explode("$del2", $value);
foreach($array2 as $key2=>$value2){
$array3[] = $value2;
}
}
$afinal = array();
for ( $i = 0; $i <= count($array3); $i += 2) {
if($array3[$i]!=""){
$afinal[trim($array3[$i])] = trim($array3[$i+1]);
}
}
return $afinal;
}
So you basically use it like this…
$string = "title=home&foo=bar&this=that";
$myVar = doubleExplode(‘&’, ‘=’, $string);
and you get back a nice array:
Array
(
[title] => home
[foo] => bar
[this] => that
)
Is that more the kind of thing you were looking for?
credits to this awesome post:
http://www.php.net/manual/en/function.explode.php#98741