Quick version of question
I'm trying to take a string like this...
BUTTONSOURCE[18]=AngellEYE_PHPClass&VERBOSITY[4]=HIGH&USER[6]=tester
and turn it into this for logging purposes...
BUTTONSOURCE[18]=AngellEYE_PHPClass
VERBOSITY[4]=HIGH
USER[6]=tester
Detailed version of question
I've always used this function to convert an NVP string to an array without any problems...
function NVPToArray($NVPString)
{
$proArray = array();
while(strlen($NVPString))
{
// name
$keypos= strpos($NVPString,'=');
$keyval = substr($NVPString,0,$keypos);
// value
$valuepos = strpos($NVPString,'&') ? strpos($NVPString,'&'): strlen($NVPString);
$valval = substr($NVPString,$keypos+1,$valuepos-$keypos-1);
// decoding the respose
$proArray[$keyval] = urldecode($valval);
$NVPString = substr($NVPString,$valuepos+1,strlen($NVPString));
}
return $proArray;
}
I pulled it from somewhere a long time ago and I've used it ever since. Now, though, I'm working with an NVP string that includes [x] values on the parameter names to show the lengh of the value. For example,
BUTTONSOURCE[18]=AngellEYE_PHPClass&VERBOSITY[4]=HIGH...
When I run a string like that through my function, though, the []'s are causing it to see it as an array index, and I end up with an array like this...
Array
(
[BUTTONSOURCE] => Array
(
[18] => AngellEYE_PHPClass
)
[VERBOSITY] => Array
(
[4] => HIGH
)
So then if I try something like this...
foreach($string_data_array as $var => $val)
{
$string_data_indiv .= $var.'='.$val.chr(13);
}
I end up with an "array to string conversion" PHP Notice and my result looks like this...
BUTTONSOURCE=Array
VERBOSITY=Array
What I'm trying to end up with is a nice break-down of the NVP string, one line at a time. So this is what I was expecting...
BUTTONSOURCE[18]=AngellEYE_PHPClass
VERBOSITY[4]=HIGH
I may be going about this a crazy way that could be a lot easier, but I've never had any issues with this sort of thing until I started working with an NVP string that includes the character count like this.
Any information on how I can resolve this issue would be greatly appreciated. Thanks!
preg_match_all()
? – Alma Do yesterday"BUTTONSOURCE[18]"
would be your string key in the array? – Alma Do yesterday