Search found 13 matches

by mralston
Tue Mar 20, 2007 2:09 pm
Forum: PHP coding => General
Topic: PHP rounding - increased precision required
Replies: 3
Views: 1385

Yep. It didn't let me off that easily though... when I came to implement it I found that our production webserver didn't have the BCMath library.
It was only a quick re-compile away, but I think it likes to keep me on my toes. :)
by mralston
Fri Mar 16, 2007 4:53 am
Forum: PHP coding => General
Topic: PHP rounding - increased precision required
Replies: 3
Views: 1385

Posted too soon! I've found the answer...

bcdiv(31,60,10)*9
by mralston
Fri Mar 16, 2007 4:37 am
Forum: PHP coding => General
Topic: PHP rounding - increased precision required
Replies: 3
Views: 1385

PHP rounding - increased precision required

Got a rounding problem.

I'm trying to to do:

31/60*9

On a calculator this comes out at 4.6499994
In PHP it comes out as 4.65

This level of precision isn't good enough, but I can't figure out how to stop PHP rounding it.

Any thoughts?
by mralston
Sun Mar 12, 2006 1:22 am
Forum: PHP coding => General
Topic: Parsing SSI style directive with regular expression
Replies: 3
Views: 1491

I don't have the solution. The last two regexes are cutdown versions of the main (first) one. I was trying to build it up step by step. The first of the bottom two regexes works, but as soon as I do the next step (add in the #) it fails. I tried matching other characters in place of the hash (and ad...
by mralston
Sat Mar 11, 2006 2:45 pm
Forum: PHP coding => General
Topic: Parsing SSI style directive with regular expression
Replies: 3
Views: 1491

Parsing SSI style directive with regular expression

Hi, I'm trying to parse what is effectively a just structured HTML comment (similar format to an SSI directive) and extract sections of it using a regular expression. I'm trying to parse something like: <!-- #type key="value" --> The regex should first of all validate that the format is correct and ...
by mralston
Thu Jan 08, 2004 1:46 pm
Forum: PHP coding => General
Topic: Date subtraction in days
Replies: 4
Views: 1069

Just once per page request.
by mralston
Thu Jan 08, 2004 1:25 pm
Forum: PHP coding => General
Topic: Date subtraction in days
Replies: 4
Views: 1069

Thanks. I was thinking of using the MySQL functions, however I've just had a reply on another forum that works a treat:

Code: Select all

function diff_days($start_date, $end_date){ 
   return floor(abs(strtotime($start_date) - strtotime($end_date))/86400);
}
by mralston
Thu Jan 08, 2004 11:38 am
Forum: PHP coding => General
Topic: Date subtraction in days
Replies: 4
Views: 1069

Date subtraction in days

How do I find the difference between two dates in days? E.g. 08/01/2004 - 05/01/2004 = 3 days The actual dates to be used will be in MySQL datetime format (yyyy-mm-dd), but I don't think that really matters for this question. I'm sure this should be really simple, but I just can't figure it out!
by mralston
Mon Nov 11, 2002 5:40 am
Forum: PHP coding => General
Topic: Getting at headers when requesting a URL
Replies: 4
Views: 1327

That's the ticket. In this case I was after the "Location" header - the page I'm requesting is a 301-page-moved redirect page. I've got it working now. :)
by mralston
Mon Nov 11, 2002 4:03 am
Forum: PHP coding => General
Topic: Getting at headers when requesting a URL
Replies: 4
Views: 1327

Actually it is possible. Somebody else just gave me the answer. fsockopen does the trick. But thanks anyway. :wink:
by mralston
Sun Nov 10, 2002 4:22 pm
Forum: PHP coding => General
Topic: Getting at headers when requesting a URL
Replies: 4
Views: 1327

Getting at headers when requesting a URL

I want to fetch a URL in PHP with fopen or popen or something.
Getting the main content of the page is fine, but I want to access the headers that the server sends back with the page. I'm sure it can be done with popen (or some command to open a tcp/ip connection to port 80?)
by mralston
Tue Oct 29, 2002 6:39 am
Forum: mySQL & php coding
Topic: Comparing the values returned by two sub-queries
Replies: 2
Views: 1511

That article was way over my head. :(
by mralston
Tue Oct 29, 2002 3:52 am
Forum: mySQL & php coding
Topic: Comparing the values returned by two sub-queries
Replies: 2
Views: 1511

Comparing the values returned by two sub-queries

I've got a MySQL database, with two tables that we're interested in: products product_id (PK) , category_id (FK) , title, description, image, price, quantity, start_date, lifetime, renewal_date orders order_id (PK) , product_id (FK) , user_id (FK) , order_date, eta, payment_method, status products c...