-2

I have a string like this:

"birs_appointment_price=&birs_appointment_duration=&birs_appointment_alternative_staff=&birs_shortcode_page_url=http%3A%2F%2Flocalhost%2Fstreamline-new%2Fworkshop%2F&_wpnonce=855cbbdefa&_wp_http_referer=%2Fstreamline-new%2Fworkshop%2F&birs_appointment_location=17858&birs_appointment_staff=-1&birs_appointment_avaliable_staff=-1%2C17859&birs_appointment_service=-1&birs_appointment_date=&birs_appointment_notes=&birs_appointment_fields%5B%5D=_birs_appointment_notes&birs_client_type=new&birs_client_name_first=&birs_client_fields%5B%5D=_birs_client_name_first&birs_client_name_last=&birs_client_fields%5B%5D=_birs_client_name_last&birs_client_email=&birs_client_fields%5B%5D=_birs_client_email&birs_field_1=&birs_client_fields%5B%5D=_birs_field_1&birs_client_fields%5B%5D=_birs_field_6&s="

I want to parse it to array in php. How to do it ?. Thanks for your help so much.

webbiedave
  • 48,414
  • 8
  • 88
  • 101

4 Answers4

0

You use parse_str for this. (http://php.net/manual/en/function.parse-str.php)

$output = array();
parse_str($str, $output);
echo $output['first'];  // value
echo $output['arr'][0]; // foo bar
echo $output['arr'][1]; // baz

Or you can parse it into local variables

$str = "first=value&arr[]=foo+bar&arr[]=baz";
parse_str($str);
echo $first;  // value
echo $arr[0]; // foo bar
echo $arr[1]; // baz
MH2K9
  • 11,951
  • 7
  • 32
  • 49
jbrahy
  • 4,228
  • 1
  • 42
  • 54
0

You can try the following : inside this foreach you will get all the get parameters and then you can store them in an array.

foreach($_GET as $key => $value) {

 //your code here

}
Robin
  • 471
  • 6
  • 18
0

use

parse_str( $string );

Refer: http://php.net/manual/en/function.parse-str.php

Tamil Selvan C
  • 19,913
  • 12
  • 49
  • 70
0
$your_str = 'birs_appointment_price=&birs_appointment_duration=&birs_appointment_alternative_staff=&birs_shortcode_page_url=http%3A%2F%2Flocalhost%2Fstreamline-new%2Fworkshop%2F&_wpnonce=855cbbdefa&_wp_http_referer=%2Fstreamline-new%2Fworkshop%2F&birs_appointment_location=17858&birs_appointment_staff=-1&birs_appointment_avaliable_staff=-1%2C17859&birs_appointment_service=-1&birs_appointment_date=&birs_appointment_notes=&birs_appointment_fields%5B%5D=_birs_appointment_notes&birs_client_type=new&birs_client_name_first=&birs_client_fields%5B%5D=_birs_client_name_first&birs_client_name_last=&birs_client_fields%5B%5D=_birs_client_name_last&birs_client_email=&birs_client_fields%5B%5D=_birs_client_email&birs_field_1=&birs_client_fields%5B%5D=_birs_field_1&birs_client_fields%5B%5D=_birs_field_6&s=';

$_VARS = array();
parse_str($your_str, $_VARS);

echo $_VARS['birs_appointment_price'];
Radu Dumbrăveanu
  • 1,266
  • 1
  • 22
  • 32