-2

I have the following string:

$string = "No+Label+name=Aaron+Smith&No+Label+email=aaron.smith@live.co.uk";

I'd like some PHP to grab the name and email address values from this string.

I'd originally tried the following but made no progress:

$str = "No+Label+name=Aaron+Smith&No+Label+email=aaron.smith@live.co.uk";
preg_match_all('#value=([^\s]+)#', $str, $matches);
echo implode(' ', $matches[1]);

I'd essentially like to say:

echo $string['No+Label+name']; // outputs name

halfer
  • 19,824
  • 17
  • 99
  • 186
michaelmcgurk
  • 6,367
  • 23
  • 94
  • 190
  • Looks like a querystring. Use https://www.php.net/manual/en/function.parse-str.php – ADyson Dec 07 '21 at 13:35
  • 1
    This is basically a query string format, so https://www.php.net/manual/en/function.parse-str.php can help you with that. (You'll only have to take into account that it will perform URL decoding, so the `+` will become spaces, in your array keys and the values.) – CBroe Dec 07 '21 at 13:36
  • Really good point @CBroe - thanks for this. Resolved now :-) – michaelmcgurk Dec 07 '21 at 13:42
  • Note that we prefer a technical style of writing here. We gently discourage greetings, hope-you-can-helps, thanks, advance thanks, notes of appreciation, regards, kind regards, signatures, please-can-you-helps, chatty material and abbreviated txtspk, pleading, how long you've been stuck, voting advice, meta commentary, etc. Just explain your problem, and show what you've tried, what you expected, and what actually happened. – halfer Dec 10 '21 at 19:19

1 Answers1

1

Not a great e answer but you can use this if you have this string

$str = "No+Label+name=Aaron+Smith&No+Label+email=aaron.smith@live.co.uk";
$temp = explode('+', $str);
$name = explode('=',$temp[2]);
$email = explode('=',$temp[5]);
echo ($name[1]);
echo "<br/>";
echo ($email[1]);