Re: [PHP] php://input
15 jan 2012 kl. 06.18 skrev Adam Tong: Hi, I am trying to read variables from input method. I am using this tuorial: http://www.lornajane.net/posts/2008/Accessing-Incoming-PUT-Data-from-PHP. Here is my code: ?php if($_SERVER['REQUEST_METHOD'] == 'GET') { echo this is a get request\n; echo $_GET['fruit']. is the fruit\n; echo I want .$_GET['quantity']. of them\n\n; } elseif($_SERVER['REQUEST_METHOD'] == 'PUT') { echo this is a put request\n; parse_str(file_get_contents(php://input),$post_vars); echo $post_vars['fruit']. is the fruit\n; echo I want .$post_vars['quantity']. of them\n\n; } ? I am using the firefox extension poster to run this example. GET works fine but when using PUT, file_get_contents(php://input) returns an empty string. I found a bug related to this: https://bugs.php.net/bug.php?id=51592 I am using xampp on win7 ( + Apache 2.2.17 + MySQL 5.5.8 (Community Server) + PHP 5.3.5 (VC6 X86 32bit) + PEAR) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Hi Adam. Although I've never worked with PUT/DELETE requests, here are my thoughts. 1) According to the manual, file_get_contents only allows URL's as filenames if fopen wrappers are enabled. Make sure that this is the case (have a look at the settings in your php ini file). Do you get any data when changing 'file_get_contents' to e.g. (as found here: http://php.net/manual/en/features.file-upload.put-method.php)? ?php /* PUT data comes in on the stdin stream */ $putdata = fopen(php://input, r); /* Open a file for writing */ $fp = fopen(myputfile.ext, w); /* Read the data 1 KB at a time and write to the file */ while ($data = fread($putdata, 1024)) fwrite($fp, $data); /* Close the streams */ fclose($fp); fclose($putdata); ? 2) Have a look in your Appache log files and make sure the client is actually making a valid PUT request. /frank -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Measuring CPU time
I haven't found a function to allow me to see elapsed CPU time to date in a function. Am I right in thinking none such exists? -- Cheers -- Tim -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Numeric help needed
Hi everyone, I am having a hard time with a numerical problem. I need to round some numbers up and I've tried $round($number) and it doesn't work so I'm misunderstanding something. For example, if a user inputs 685000 I need it to round up to 69 or if they input 149560 I need it to round up to 15. What is the correct way to do this as everything I have tried doesn't seem to affect the user inputted figure at all. Anyway help would REALLY be appreciated, I'm sure it's really simple but for the life of me I'm stumped on why it's not working. Chris
Re: [PHP] Numeric help needed
Sent from my iPhone On Jan 15, 2012, at 8:25 PM, Christopher J Payne oxygene...@gmail.com wrote: Hi everyone, I am having a hard time with a numerical problem. I need to round some numbers up and I've tried $round($number) and it doesn't work so I'm misunderstanding something. For example, if a user inputs 685000 I need it to round up to 69 or if they input 149560 I need it to round up to 15. What is the correct way to do this as everything I have tried doesn't seem to affect the user inputted figure at all. Anyway help would REALLY be appreciated, I'm sure it's really simple but for the life of me I'm stumped on why it's not working. Maybe it's just a typo in your email but you put a $ infront of round() try removing that and see if it helps. If not are there any error messages that are showing up? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Numeric help needed
Hi Jason, I've tried lots of different things, including: echo br . round(68500, 1000) . ROUNDED; thinking that might be it, but i'm stumped This is the example I was given (And have to go by): If the loan amount is $68500.00, the insurace will be based on $69000.00 as the amount is always rounded up to the next $1000. Maybe i'm just looking at it wrong but i'm stumped. Chris On Sun, Jan 15, 2012 at 8:41 PM, Jason Pruim li...@pruimphotography.com wrote: Sent from my iPhone On Jan 15, 2012, at 8:25 PM, Christopher J Payne oxygene...@gmail.com wrote: Hi everyone, I am having a hard time with a numerical problem. I need to round some numbers up and I've tried $round($number) and it doesn't work so I'm misunderstanding something. For example, if a user inputs 685000 I need it to round up to 69 or if they input 149560 I need it to round up to 15. What is the correct way to do this as everything I have tried doesn't seem to affect the user inputted figure at all. Anyway help would REALLY be appreciated, I'm sure it's really simple but for the life of me I'm stumped on why it's not working. Maybe it's just a typo in your email but you put a $ infront of round() try removing that and see if it helps. If not are there any error messages that are showing up? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Numeric help needed
On 16/01/2012, at 2:48 PM, Chris Payne wrote: Hi Jason, I've tried lots of different things, including: echo br . round(68500, 1000) . ROUNDED; thinking that might be it, but i'm stumped This is the example I was given (And have to go by): If the loan amount is $68500.00, the insurace will be based on $69000.00 as the amount is always rounded up to the next $1000. Maybe i'm just looking at it wrong but i'm stumped. Chris The round() function only rounds decimal values. You can use this to emulate rounding to a near power of ten by dividing, rounding, then multiplying again. i.e. echo br . round(68500/1000) * 1000 . ROUNDED; --- Simon Welsh Admin of http://simon.geek.nz/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Numeric help needed
On 1/15/2012 8:48 PM, Chris Payne wrote: Hi Jason, I've tried lots of different things, including: echo br . round(68500, 1000) . ROUNDED; thinking that might be it, but i'm stumped This is the example I was given (And have to go by): If the loan amount is $68500.00, the insurace will be based on $69000.00 as the amount is always rounded up to the next $1000. Maybe i'm just looking at it wrong but i'm stumped. Chris On Sun, Jan 15, 2012 at 8:41 PM, Jason Pruimli...@pruimphotography.com wrote: Sent from my iPhone On Jan 15, 2012, at 8:25 PM, Christopher J Payneoxygene...@gmail.com wrote: Hi everyone, I am having a hard time with a numerical problem. I need to round some numbers up and I've tried $round($number) and it doesn't work so I'm misunderstanding something. For example, if a user inputs 685000 I need it to round up to 69 or if they input 149560 I need it to round up to 15. What is the correct way to do this as everything I have tried doesn't seem to affect the user inputted figure at all. Anyway help would REALLY be appreciated, I'm sure it's really simple but for the life of me I'm stumped on why it's not working. Maybe it's just a typo in your email but you put a $ infront of round() try removing that and see if it helps. If not are there any error messages that are showing up? http://php.net/manual/en/function.round.php From the page: |?php echo round(3.4); // 3 echo round(3.5); // 4 echo round(3.6); // 4 echo round(3.6, 0); // 4 echo round(1.95583, 2); // 1.96 echo round(1241757, -3); // 1242000 echo round(5.045, 2); // 5.05 echo round(5.055, 2); // 5.06 ? |
Re: [PHP] Numeric help needed
On Jan 15, 2012, at 19:00, Simon J Welsh si...@welsh.co.nzmailto:si...@welsh.co.nz wrote: On 16/01/2012, at 2:48 PM, Chris Payne wrote: If the loan amount is $68500.00, the insurace will be based on $69000.00 as the amount is always rounded up to the next $1000. The round() function only rounds decimal values. You can use this to emulate rounding to a near power of ten by dividing, rounding, then multiplying again. i.e. echo br . round(68500/1000) * 1000 . ROUNDED; You can also pass a second parameter to round() that indicates the precision to round to. If you pass a negative precision value, you can round to higher-order digits. For example, pass -3 to round to the nearest thousand. Having said that, based on the quote above, I believe this would be an incorrect solution to the problem. It sounds like the value is simply always rounded up to the nearest thousand, which means round() is not the function to use as it will sometimes round down. Instead ceil() should be used, as it always rounds up to the next whole number/integer. It lacks a precision argument, however, so the OP would need to use the divide-adjust-multiple trick you provided to make it work. That is, something like this: $newValue = ceil(68500 / 1000) * 1000 Numbers smaller than 1000 will need to be handled as an edge case, since this algorithm will adjust them to zero for you (same as when using round(), incidentally). If negative numbers are valid inputs, they'll also need careful review to ensure correct behavior. Hope that helps. -- Bob Williams Notice: This communication, including attachments, may contain information that is confidential. It constitutes non-public information intended to be conveyed only to the designated recipient(s). If the reader or recipient of this communication is not the intended recipient, an employee or agent of the intended recipient who is responsible for delivering it to the intended recipient, or if you believe that you have received this communication in error, please notify the sender immediately by return e-mail and promptly delete this e-mail, including attachments without reading or saving them in any manner. The unauthorized use, dissemination, distribution, or reproduction of this e-mail, including attachments, is prohibited and may be unlawful. If you have received this email in error, please notify us immediately by e-mail or telephone and delete the e-mail and the attachments (if any).
Re: [PHP] Numeric help needed
On 1/15/2012 9:24 PM, Robert Williams wrote: On Jan 15, 2012, at 19:00, Simon J Welshsi...@welsh.co.nzmailto:si...@welsh.co.nz wrote: On 16/01/2012, at 2:48 PM, Chris Payne wrote: If the loan amount is $68500.00, the insurace will be based on $69000.00 as the amount is always rounded up to the next $1000. The round() function only rounds decimal values. You can use this to emulate rounding to a near power of ten by dividing, rounding, then multiplying again. i.e. echo br . round(68500/1000) * 1000 . ROUNDED; round() rounds floating point which I suppose includes decimals, but decimal tends to have a fixed number of decimal places. float *round* ( float $val [, int $precision= 0 [, int $mode= PHP_ROUND_HALF_UP ]] )
[PHP] Thank you all for your help
Hi there, A big thank you to all of you who took time to help me with my numeric problem from earlier, it's been a huge help :-) Chris -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php