आप कच्चे पद डेटा पढ़ सकते हैं। उदाहरण के लिए:
<fieldset>
<legend>Data</legend>
<?php
$data = file_get_contents("php://input");
echo $data."<br />";
?>
</fieldset>
<fieldset>
<legend>Form</legend>
<form method="post" action="formtest.php">
<input type="checkbox" value="val1" name="option"/><br />
<input type="checkbox" value="val2" name="option"/><br />
<input type="submit" />
</form>
</fieldset>
दोनों बॉक्स और उत्पादन हो जाएगा:
option=val1&option=val2
यहाँ एक है लाइव डेमो । तुम सब तो क्या करना है स्ट्रिंग अपने आप को पार्स करने के लिए, एक उपयुक्त प्रारूप में है। यहाँ एक समारोह है कि ऐसा ही कुछ करता है की एक उदाहरण है:
function parse($data)
{
$pairs = explode("&", $data);
// process all key/value pairs and count which keys
// appear multiple times
$keys = array();
foreach ($pairs as $pair) {
list($k,$v) = explode("=", $pair);
if (array_key_exists($k, $keys)) {
$keys[$k]++;
} else {
$keys[$k] = 1;
}
}
$output = array();
foreach ($pairs as $pair) {
list($k,$v) = explode("=", $pair);
// if there are more than a single value for this
// key we initialize a subarray and add all the values
if ($keys[$k] > 1) {
if (!array_key_exists($k, $output)) {
$output[$k] = array($v);
} else {
$output[$k][] = $v;
}
}
// otherwise we just add them directly to the array
else {
$output[$k] = $v;
}
}
return $output;
}
$data = "foo=bar&option=val1&option=val2";
print_r(parse($data));
आउटपुट:
Array
(
[foo] => bar
[option] => Array
(
[0] => val1
[1] => val2
)
)
कुछ मामलों में जहां इस समारोह के रूप में हालांकि उम्मीद से काम नहीं करता है, तो सावधान रहना हो सकता है।