Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Is it possible to POST a fractional number from a form?
- <select name="inverse_num">
- <option value="2">2 </option>
- <option value="1">1 </option>
- <option value="1/2">1/2 </option>
- <option value="1/3">1/3 </option>
- </select>
- $my_inverse=1/($_POST[inverse_num]); // returns 1 , but..
- $my_inverse=1/(1/2); // returns 2, which is required.
- function simple_fractions ($value) {
- if (is_numeric($value)) {
- return $value;
- }
- preg_match('/^(d+)/(d+)$/', $value, $matches);
- if ($matches[1] && $matches[2]) {
- return $matches[0] / $matches[1];
- }
- if ($matches[1] == 0) {
- return 0;
- }
- return false;
- }
- $my_inverse=1/($_POST[inverse_num]); // array keys shall be quoted
- $my_inverse=1/(1/2);
- $my_inverse=1/"1/2";
- $my_inverse=1/(1/2);
- <select name="inverse_num">
- <option value="a">2 </option>
- <option value="b">1 </option>
- <option value="c">1/2 </option>
- <option value="d">1/3 </option>
- </select>
- if($_POST['inverse_num'] == 'a'){
- $value = 2;
- }elseif($_POST['inverse_num'] == 'b'){
- $value = 1;
- }elseif($_POST['inverse_num'] == 'c'){
- $value = 1/2;
- }elseif($_POST['inverse_num'] == 'd'){
- $value = 1/3;
- }
Add Comment
Please, Sign In to add comment