I'm passing a javascript variable in my PHP form that gets passed as formatted below:
<form onsubmit='$("#crop_cords").val($.param(c).toString()); return true;' id="process_image_form" action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
crop_cords='x=50&y=50&x2=400&y2=400&w=350&h=350'
Is there a better way to parse the value for crop_cords on the server side or do I need to use split and/or explode? I was hoping to find a cleaner solution. The result should look like this:
x=50
y=50
x2=400
y2=400
w=350
h=350
You are looking for parse_str
.
$crop_cords='x=50&y=50&x2=400&y2=400&w=350&h=350';
parse_str($crop_cords, $parsed);
print_r($parsed);
You can use parse_str to parse the string as if it were the querystring:
$params = array();
parse_str($_POST['crop_cords'], $params);