Re: [PHP] PHP vs JAVA

2013-08-20 Thread Pete Ford

On 20/08/13 15:00, Tedd Sperling wrote:

Hi guys:

A teacher at my college made the statement that JAVA for Web Development is 
more popular than PHP.

Where can I go to prove this right or wrong -- and/or -- what references do any 
of you have to support your answer? (sounds like a teacher, huh?)

Here are my two references:

http://w3techs.com/technologies/details/pl-php/all/all

http://w3techs.com/technologies/history_overview/programming_language/ms/y

But I do not know how accurate they are.

What say you?

Cheers,


tedd

___
tedd sperling
t...@sperling.com


tedd,

Java is a meticulously-constructed language with very strict typing and 
a large commercial organisation which purports to support and develop it.
PHP is a scruffy heap of loosely typed cruft which is easy to knock 
together and build big things from, but has a semi-commercial and 
community support structure.
Guess which one the big commercial organistations (banks, industry etc.) 
prefer to trust?
Guess which is then popular for college courses since it provides the 
students with a basis in something that is commercially desirable?
From my personal point of view, I started with BASIC, then FORTRAN (in 
a scientific environment), then C/C++, then Java (which I saw as the 
language C++ should have been), and then moved on to PHP in a search to 
find a way of building web apps in the sort of timescales that 
small-medium enterprises are prepared to accept.

Popularity is in the eye of the beholder...

Cheers
Pete

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] PHP is Zero

2013-06-13 Thread Pete Ford

On 13/06/13 08:59, BUSCHKE Daniel wrote:

Hi all,
I want to start a discussion about a PHP behaviour that drives me crazy for 
years. For the beginning I would like you to guess what the result of the 
following snippet will be:

var_dump('PHP' == 0);

I know the difference of == and === but the result was unexcpected for me. And I hope it 
is also for you. The result is simply true. Why is it true? I guess this 
happens because of the conversion from 'PHP' to a number which will be 0 in PHP. And of 
course 0 equals 0. There are several points that I just want to drop into this 
mailinglist to discuss about:

1. Why? :)


42


2. Why is PHP converting the String into a Number instead of converting the 
Number into a String? (If my guess concerning the behaviour is correct)


Since PHP is a weakly-typed language, it has to choose one way or the 
other. The behaviour *is* predictable if you know what the rule is (I'm 
sure the order of conversion is documented somewhere).



3. Why is PHP throwing data away which has the developer explicit given to the 
interpreter?


Because PHP is weakly-typed, the developer is not being sufficiently 
explicit. Try


php -r 'var_dump(intval('PHP') == 0);'

and

php -r 'var_dump('PHP' == strval(0));'

to see explicit code. Anything less is implicit.


4. Why does var_dump(0 == 'PHP'); has the same result as the snippet above? 
This meens that the equal operator is not explictly implemented in the string 
or integer?


The rule is consistent: it always converts the string to an integer 
whatever the order.



5. Thats a bug I have opend: https://bugs.php.net/bug.php?id=51739 where I also had the same 
problems because 8315e839da08e2a7afe6dd12ec58245d was converted into float(INF) by 
throwing everything starting from da08.. away.



That's a very different proposition, and probably has more to do with 
word size: float is 32-bit, so only the first 32 bits are used and if 
anything else is found the conversion falls back to INF. To handle 
really big integers like 8315e839da08e2a7afe6dd12ec58245d you probably 
need a more specialist library (or language)



I am using PHP since the year 2000. This means I have 13 years of experience in PHP and I really 
would like you to NOT just answer works as designed. I know it works as designed but I 
want to discuss the design. Also I know that the fuzzy behaviour of type conversion is 
a main feature of PHP. I guess this is one point which makes PHP that successfull. But - in my 
opinion - the described behaviour is to fuzzy and just confuses developers.


The weak typing *is* a feature of PHP: other languages are more suitable 
when you need more enforcement of types: Java, for example.
With all due respect to an experience programmer, years of experience do 
not make up for a limited tool set.


Best Regards
Daniel Buschke



Cheers
Pete

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: AW: [PHP] PHP is Zero

2013-06-13 Thread Pete Ford

On 13/06/13 10:44, BUSCHKE Daniel wrote:

Hi,
thanks for your answer. Especially the answer 42 made me laughing :)

My Why questions should be understand as Why must it be like that questions.


On 13/06/13 08:59, BUSCHKE Daniel wrote:
5. Thats a bug I have opend: https://bugs.php.net/bug.php?id=51739 where I also had the same 
problems because 8315e839da08e2a7afe6dd12ec58245d was converted into float(INF) by 
throwing everything starting from da08.. away.


That's a very different proposition, and probably has more to do with word 
size: float is 32-bit, so only the first 32 bits are used and if anything else 
is found the conversion falls back to INF. To handle really big integers like 
8315e839da08e2a7afe6dd12ec58245d you probably need a more specialist library 
(or language)


For me it is not. PHP throws things away during conversion. In my opinion a 
language (compiler, interpreter whatever) should not do that. Never ever! 
Either it is able to convert the value or it is not.

What about of returning null instead of 0 if the conversion is not perfect? 
So intval('F') could return NULL and intval('0') could return 0.

Regards
Daniel




I've had a bit of a play with your big hex number, and the problem is 
much more subtle: floatval(8315e839da08e2a7afe6dd12ec58245d) is 
truncated at 8315e839 because it tries to parse it as an exponential 
float: floatval(8315e83) becomes 8.315 x 10^86, but 8.315e839 is 8.315 
x 10^842 which is (as far as PHP is concerned) an infinitely large number!


So we try replacing that first 'e' with a 'd' (for example) and then

php -r 'var_dump(floatval(8315d839da08e2a7afe6dd12ec58245d));'
returns
float(8315)

It gives up when it finds a non-numeric character (as the documentation 
would tell you)


Perhaps what you need is

php -r 'var_dump(floatval(0x8315e839da08e2a7afe6dd12ec58245d));'

float(1.7424261578436E+38)

In other words, you need to tell the interpreter that you have a number 
(in base-16) rather than a string.


A proper strongly-typed language would just tell you that it's nonsense...

Cheers
Pete


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: Tree menu list in php

2011-07-27 Thread Pete Ford

On 26/07/11 18:20, alekto wrote:

Hi,
is there a way to create a tree menu list only by using php/html/css?
I found some, but they are all in JavaScript, do I have to make them by using 
JavaScript or is there a way in php as well?

This is how I imagine the tree menu should look like:


v First level
  Second level
  Second level
v Second level
 Third level
 Third level
 Third level
 Second level
 Second level

(  = menu is closed, v  = menu is open )


Cheers!


Look, I know this is loopy and I haven't tried it (for the protection of my 
sanity, mainly), but how about the tree being an image generated using PHP, and 
then used as an image map to submit the page every time a click is made on the 
image - you could then use the coordinates of the click to determine the new 
state of the tree and render an appropriate image for it...


I'll get my coat...

Pete

--
Peter Ford, Developer phone: 01580 89 fax: 01580 893399
Justcroft International Ltd.  www.justcroft.com
Justcroft House, High Street, Staplehurst, Kent   TN12 0AH   United Kingdom
Registered in England and Wales: 2297906
Registered office: Stag Gates House, 63/64 The Avenue, Southampton SO17 1XS

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Constants in strings

2011-07-08 Thread Pete Ford

On 06/07/11 17:33, Robert Williams wrote:

Where I've made most use of heredocs is when I want to do nothing but define a 
bunch of
long strings in one file.


I find the most useful thing about heredocs is that they don't care about 
quotation marks, so I often use them for SQL statements where I might have a 
mixture of ' and 


eg.

$sql =EoSQL
SELECT
foo AS Foo
FROM Bar
WHERE baz='quux'
EoSQL;


--
Peter Ford, Developer phone: 01580 89 fax: 01580 893399
Justcroft International Ltd.  www.justcroft.com
Justcroft House, High Street, Staplehurst, Kent   TN12 0AH   United Kingdom
Registered in England and Wales: 2297906
Registered office: Stag Gates House, 63/64 The Avenue, Southampton SO17 1XS

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Ftp upload

2011-06-15 Thread Pete Ford

On 15/06/11 01:24, Marc Guay wrote:

I bought a 1GB external hard drive for $1000.  Did I just choke on my lunch?


If that was about 20 years ago, then it would be fine!

--
Peter Ford, Developer phone: 01580 89 fax: 01580 893399
Justcroft International Ltd.  www.justcroft.com
Justcroft House, High Street, Staplehurst, Kent   TN12 0AH   United Kingdom
Registered in England and Wales: 2297906
Registered office: Stag Gates House, 63/64 The Avenue, Southampton SO17 1XS

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] PHP download page blocking other HTTP requests

2011-06-07 Thread Pete Ford

On 06/06/11 21:07, Richard Quadling wrote:

On 6 June 2011 13:55, Pete Fordp...@justcroft.com  wrote:

Is there something on the Apache/PHP end that might be causing this
blocking? (Apache 2.2.10, PHP 5.2.14)


The browser and / or OS may be obeying the settings about the number
of simultaneous connections per host.
http://support.microsoft.com/kb/183110 /
http://www.ietf.org/rfc/rfc2616.txt 8.1.4 Practical Considerations ...

   Clients that use persistent connections SHOULD limit the number of
simultaneous connections that they maintain to a given server. A
single-user client SHOULD NOT maintain more than 2 connections with
any server or proxy. A proxy SHOULD use up to 2*N connections to
another server or proxy, where N is the number of simultaneously
active users. These guidelines are intended to improve HTTP response
times and avoid congestion.

Also, (from googling)
http://forums.serverbeach.com/showthread.php?6192-Max-Concurrent-Connections-Per-Host,
mod_throttle and/or mod_bandwidth may be capable of restricting the
number and/or speed of connections.



Thanks Richard,

There's no mod_throttle or mod_bandwidth, but I SHOULD have remembered RFC2616. 
I'll look into working with that, although I'm having trouble reproducing the 
problem since my dev machine sits on the same network as the server and the 
files come down too quickly!

Maybe I can use a redirect or something to force a new connection...


--
Peter Ford, Developer phone: 01580 89 fax: 01580 893399
Justcroft International Ltd.  www.justcroft.com
Justcroft House, High Street, Staplehurst, Kent   TN12 0AH   United Kingdom
Registered in England and Wales: 2297906
Registered office: Stag Gates House, 63/64 The Avenue, Southampton SO17 1XS

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] PHP download page blocking other HTTP requests

2011-06-06 Thread Pete Ford

I have a file download 'guardian' page which does something like this:

$size = filesize($path);
$fi = @finfo_file($path, FILEINFO_MIME_TYPE);
@header('Content-type: ' . $fi);
@header('Content-Length: ' . $size);
@readfile($path);
exit;

($path is derived from parameters in the request, including checks for nasties 
and some access control checks in the system)


When a link is clicked which points to this script, the file is downloaded (well 
and good...), but in Firefox (3.x, 4.x at least), it seems to block any further 
interaction with the browser until the download is complete - some of the files 
are 60Gb and the server is on a 2mbit line, so it can take some time to download.


Is there something on the Apache/PHP end that might be causing this blocking? 
(Apache 2.2.10, PHP 5.2.14)
I suspect not, since using Chrome as the browser doesn't appear to have the same 
problem, but I wondered whether there was some way that FF was handling the 
headers might be causing it.
I can't seem to devise a suitable Google search to get any mention of similar 
behaviour so I thought I'd ask some experts :)


--
Peter Ford, Developer phone: 01580 89 fax: 01580 893399
Justcroft International Ltd.  www.justcroft.com
Justcroft House, High Street, Staplehurst, Kent   TN12 0AH   United Kingdom
Registered in England and Wales: 2297906
Registered office: Stag Gates House, 63/64 The Avenue, Southampton SO17 1XS

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Closing Session (Revisited)

2011-05-23 Thread Pete Ford

On 22/05/11 06:46, Roger Riordan wrote:

On Thu, 05 May 2011 08:28:53 -0400, sstap...@mnsi.net (Steve Staples) wrote:


On Thu, 2011-05-05 at 21:41 +1000, Roger Riordan wrote:


I have developed a common engine which I use for several different websites. I 
had been
using PHP 5.2.? and IE6 (yes; I know!), and had been able to have multiple 
sessions open
at once, displaying the same or different websites, without them interfering 
with each
other. This was incredibly useful; I could be looking at, or even edit, 
different parts of
the same, or different, websites simultaneously without any problems.

But I recently had a hard disk crash and had to re-install all the system 
software. Now I
have PHP 5.3 and IE 8, and find that if I try to do this the various sessions 
interfere
with each other. From the above comment I gather that this is because IE 8 
combines all
the instances, whereas previously each instance was treated as a different user.

Is there any simple way to make IE 8 treat each instance as a new user, or 
should I switch
to Chrome and use the Incognito feature?

Roger Riordan AM
http://www.corybas.com/



The Incognito feature wont give you the results you're looking for.
 From my experience, the incognito window(s) and tab(s) share the same
memory/cookie/session space, which is different from the main window...
which means you will run into the same issue.

Once you close all your incognito windows/tabs, you will release those
cookies/sessions/memory space and if you open a new one afterwards, then
you will be fine, but if one tabs stays open, no go :(

Have you looked at the http://ca3.php.net/session_name function, and
putting that into your site just after your session_start() ?  I believe
that will fix your issues (as long as your session names are unique),
but i am not 100% sure.

Steve



Thank you for this suggestion. This has solved the more serious half of my 
problems; I can
easily generate a different session name for each website, so that the various 
websites
don't interfere with each other, but I have not been able to devise a way to 
differentiate
between multiple sessions of the same website.

For example, if I open one copy of a website as a visitor I am shown as 
Visitor, but if I
then open another window, and log in as Manager, then go back to the first 
window I am
shown as Manager (with appropriate privileges) there also.

The only way I can think of to overcome this would be to generate a new named 
session
every time I log in, and then to pass the session name as a parameter every 
time I load a
new page. Unfortunately my program is sufficiently complicated that this is 
effectively
impractical, as it would involve tracking down and modifying every point in the 
program at
which a new page can be launched.

It also has a theoretical disadvantage that if someone bookmarks a page they 
will book
mark the session name, but this can fairly readily be overcome.

Is there any alternative way in which a different session name (or equivalent 
flag) can be
attached to each instance of the browser?

(Effectively these problems only affect the developer, as they only apply to 
multiple
instances of the same browser on the same PC.)


PS. At this stage I devised a really nasty kludge, which enables me to run 
multiple copies
without them interfering. In my program new pages are always launched by a 
command of the
general type:

http://localhost/cypalda.com/index.php?level=1item=22

This loads the file index.php, which is a very brief file in the public 
directory
(cypalda.com in this case). It sets a couple of constants and then transfers 
control to a
file Begin.php, in a private directory. This in turn sets up a whole lot more 
constants,
and then transfers control to the main program, which is common to 5 different 
websites.

I realised that if I specify the session name in index.php, I can make several 
copies of
this file, e.g. index.php, index1.php, index2.php, each of which specified a 
different
session name. I thought this still left me the problem of modifying all the 
points at
which a new page was launched, but then I found that by great good fortune (or 
foresight!)
I had defined a constant $home_page = index.php, and always launched a new page 
with the
basic command
echo ('a href='.$home_page.'?ident=' ...');

So all I had to do to achieve the desired outcome was to specify a different 
$homepage in
each copy of index.php. Then, once I had launched a particular copy of 
index.php, that
instance of the browser would always load the session appropriate to that copy.

Even better, if I upload the various versions of index.php, I can run multiple 
copies of
the public website on the same PC without them interfering.


Roger Riordan AM
http://www.corybas.com/


Depending upon how your session persistence works, can you not just specify a 
different location to store session data for each possible mode of login?
I have an application which does something similar, 

[PHP] Re: Date validation

2011-05-23 Thread Pete Ford

On 20/05/11 16:29, Geoff Lane wrote:

On Friday, May 20, 2011, Peter Lind wrote:


Try:



$date = new DateTime($date_string_to_validate);
echo $date-format('Y-m-d');


Many thanks. Unfortunately, as I mentioned in my OP, the DateTime
class seems to be 'broken' for my purposes because it uses strtotime()
to convert input strings to date/time. Rather than fail when presented
with an invalid date, strtotime() returns the 'best fit' if possible.
This can be seen from:

$date = new DateTime('30 Feb 1999');
echo $date-format('Y-m-d');

which results in 1999-03-02 even though 30 Feb is an invalid date.



If you could programmatically determine the format of the input, you could parse 
the date using DateTime and then rewrite it using the same format as the input, 
and compare those.
Now that starts to work if you can *control* the format of the input, or at 
least limit it to some familiar options.


So maybe:

$userInput = '30 Feb 1999';
$dateTest = new DateTime($userInput);
if ($userInput===$dateTest-format('Y-m-d') ||
$userInput===$dateTest-format('d M Y'))
{
echo 'Date is valid';
}
else
{
echo 'Not valid';
}

It starts to get logn-winded after a while, and doesn't rule out ambiguous 
cases...
Or split the date input into pieces in the form (if possible) and then you can 
validate the date how you like


$userInput = $_POST['year'].'-'.$_POST['month'].'-'.$_POST['day'];
$dateTest = new DateTime($userInput);
if ($userInput===$dateTest-format('Y-m-d'))
{
echo 'Date is valid';
}
else
{
echo 'Not valid';
}


Finally, for some applications I have made an AJAX (javascript + PHP) 
implementation which provides feedback to the user as they type in the date 
field: every time a character is typed in the box, the backend is asked to parse 
it and then format it in an unambiguous way and send it back to the client. That 
way the user can *see* if what they are typing is valid...
Of course, you *still* have to validate it when it's posted (and the network 
overhead might be too much).




--
Peter Ford, Developer phone: 01580 89 fax: 01580 893399
Justcroft International Ltd.  www.justcroft.com
Justcroft House, High Street, Staplehurst, Kent   TN12 0AH   United Kingdom
Registered in England and Wales: 2297906
Registered office: Stag Gates House, 63/64 The Avenue, Southampton SO17 1XS

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: Date validation

2011-05-23 Thread Pete Ford

On 23/05/11 13:12, tedd wrote:

At 9:47 AM +0100 5/23/11, Pete Ford wrote:

Finally, for some applications I have made an AJAX (javascript + PHP)
implementation which provides feedback to the user as they type in the
date field: every time a character is typed in the box, the backend is
asked to parse it and then format it in an unambiguous way and send it
back to the client. That way the user can *see* if what they are
typing is valid...
Of course, you *still* have to validate it when it's posted (and the
network overhead might be too much).


That would be interesting to see.

With a little work, I envision a way to alleviate the Europe/US date
format difference. (i.e., day/month/year : Europe vs month/day/year : US).

As the user typed in the date, the day/month problem could be shown via
string-month (i.e., Jan... ).

How does yours work?

Cheers,

tedd


Ah, now you're asking.
I'll have to try and extract the code into a sanitised form for public 
consumption: give me a little time...
But yes, the string fed back to the user gives the month as a string, to avoid 
confusion with numeric months.


--
Peter Ford, Developer phone: 01580 89 fax: 01580 893399
Justcroft International Ltd.  www.justcroft.com
Justcroft House, High Street, Staplehurst, Kent   TN12 0AH   United Kingdom
Registered in England and Wales: 2297906
Registered office: Stag Gates House, 63/64 The Avenue, Southampton SO17 1XS

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Warning: session_start()

2011-05-19 Thread Pete Ford

On 19/05/11 10:37, Tim Streater wrote:

On 19 May 2011 at 10:20, Richard Quadlingrquadl...@gmail.com  wrote:


On 18 May 2011 19:15, Nazishnaz...@jhu.edu  wrote:



Hi everyone,



!---
WHEN USER CLICKS 'ENTER' TO LOGIN
!
?php


code, code, code.


?


The session cookie must be sent prior to any output. Including, but
not limited to, comments, whitespace, HTML code, etc.



2 - Remove all white space. Personally, this is the route I would use.


For the sake of completeness, that is whitespace *outside* the?php ?  tags.

tim



The comment should really be inside the php block:

?php
/*
WHEN USER CLICKS 'ENTER' TO LOGIN
*/

... code ...
?

otherwise (notwithstanding the session_start() problem) you'll get the comments 
in you HTML source - probably not what you wanted...




--
Peter Ford, Developer phone: 01580 89 fax: 01580 893399
Justcroft International Ltd.  www.justcroft.com
Justcroft House, High Street, Staplehurst, Kent   TN12 0AH   United Kingdom
Registered in England and Wales: 2297906
Registered office: Stag Gates House, 63/64 The Avenue, Southampton SO17 1XS

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: XML... Useful or another layer of complexity?

2011-04-04 Thread Pete Ford

On 03/04/11 19:41, Jason Pruim wrote:

So the subject says it all... And yes I know this isn't related to PHP but it's 
the weekend and I trust the opinions on this list more then any other list I 
have seen. I've been doing alot of reading on XML and honestly it looks pretty 
cool... BUT the question is... Is it truly useful or is it just another layer 
that we have to write?

 From what I can tell it looks like it could stabilize some of my programming 
in regards to databases, and possibly if I have to move information from one 
application to another.

But is it worth the added coding or should I just interact with the pieces 
directly?

Thoughts? Questions? Flames? :)




Yes :)

--
Peter Ford, Developer phone: 01580 89 fax: 01580 893399
Justcroft International Ltd.  www.justcroft.com
Justcroft House, High Street, Staplehurst, Kent   TN12 0AH   United Kingdom
Registered in England and Wales: 2297906
Registered office: Stag Gates House, 63/64 The Avenue, Southampton SO17 1XS

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: mysql_num_rows()

2011-02-24 Thread Pete Ford

On 22/02/11 14:40, Gary wrote:

Pete Fordp...@justcroft.com  wrote in message
news:76.48.39221.054c3...@pb1.pair.com...

On 22/02/11 13:59, Gary wrote:

Pete Fordp...@justcroft.com   wrote in message
news:a4.c0.39221.b3ca3...@pb1.pair.com...

On 22/02/11 05:40, Gary wrote:

Can someone tell me why this is not working?  I do not get an error
message,
the results are called and echo'd to screen, the count does not work, I
get
a 0 for a result...



$result = mysql_query(SELECT * FROM `counties` WHERE name =
'checked')
or
die(mysql_error());

if ( isset($_POST['submit']) ) {
for($i=1; $i=$_POST['counties']; $i++) {
if ( isset($_POST[county$i] ) ) {
echo You have chosen . $_POST[county$i].br/;
   }
   }
}

$county_total=mysql_num_rows($result);

while($row = mysql_fetch_array($result))
{$i++;
   echo $row['name'];
}
$county_total=mysql_num_rows($result);
echo $county_total;

echo 'You Have '  .  $county_total  .  ' Counties ';

?


The first thing I see is that you do
$county_total=mysql_num_rows($result)
twice. Now I'm not to sure, but it is possible that looping over
mysql_fetch_array($result) moves an array pointer so the count is not
valid after the operation... that's a long shot.

But since you are looping over the database records anyway, why not just
count them as you go? Isn't $i the number of counties after all the
looping?


--
Peter Ford, Developer phone: 01580 89 fax: 01580
893399
Justcroft International Ltd.
www.justcroft.com
Justcroft House, High Street, Staplehurst, Kent   TN12 0AH   United
Kingdom
Registered in England and Wales: 2297906
Registered office: Stag Gates House, 63/64 The Avenue, Southampton SO17
1XS



Peter

Thank you for your reply.

I did notice that I had the $county_total=mysql_num_rows($result) twice.
I
had moved and removed it, always getting either a 0 or 1 result.

I put up another test page with

$result = mysql_query(SELECT * FROM `counties` ) or die(mysql_error());

$tot=mysql_num_rows($result);
echo $tot;

?

And it worked fine.

I have tried count() as well as mysql_num_rows() but am getting the same
result.

Could you explain what you mean by count them as I go?

Again, Thank you for your reply.

Gary



__ Information from ESET Smart Security, version of virus
signature database 5895 (20110222) __

The message was checked by ESET Smart Security.

http://www.eset.com






Well,

Lets go back to your original code and cut out the decoration:

$result = mysql_query(SELECT * FROM `counties` WHERE name = 'checked')
$county_total=mysql_num_rows($result);
while($row = mysql_fetch_array($result))
{
 echo $row['name'];
}
echo $county_total;

That code should do pretty much what you want...

But, because you only show the number of records AFTER the loop, you could
do:

$result = mysql_query(SELECT * FROM `counties` WHERE name = 'checked')
$county_total = 0;
while($row = mysql_fetch_array($result))
{
 echo $row['name'];
 $county_total++;
}
echo $county_total;



Peter

Thank you for your suggestion...btw cut out the decoration  LOL

I'm sorry to report it did not work. I tried various configurations of it
but to no avail.

Any other suggestions?

Again, thank you for your help.

Gary



__ Information from ESET Smart Security, version of virus signature 
database 5895 (20110222) __

The message was checked by ESET Smart Security.

http://www.eset.com






Gary,

I'd probably need a bit more detail on the it did not work to go much further!
Actually, it looks like I missed a semicolon on the mysql_query line in *both* 
versions - maybe that was the problem...
Do you have access to your server logs, to see if any errors are reported when 
you run this?


Cheers
Peter

--
Peter Ford, Developer phone: 01580 89 fax: 01580 893399
Justcroft International Ltd.  www.justcroft.com
Justcroft House, High Street, Staplehurst, Kent   TN12 0AH   United Kingdom
Registered in England and Wales: 2297906
Registered office: Stag Gates House, 63/64 The Avenue, Southampton SO17 1XS

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: Dynamically Created Checkboxes

2011-02-23 Thread Pete Ford

This bit?

On 22/02/11 22:06, Gary wrote:

for($i=1; $i=$_POST['counties']; $i++) {
if ( isset($_POST[county{$i}] ) ) {


You loop over $_POST['counties'] and look for $_POST[county$i]

I suspect that there is no field 'counties' in your form, so the server is 
complaining about the missing index - seems likely that the production server

is not showing the error, but instead just giving up on the page.

I think the IE7/Firefox browser difference is a red herring: it wasn't actually 
working in any browser, or the code changed between tests. Remember, PHP is 
server side and generates HTML (or whatever). Unless you tell the PHP what 
browser you are using and write PHP code to take account of that (not generally 
recommended) then the server output is the same regardless of browser.


--
Peter Ford, Developer phone: 01580 89 fax: 01580 893399
Justcroft International Ltd.  www.justcroft.com
Justcroft House, High Street, Staplehurst, Kent   TN12 0AH   United Kingdom
Registered in England and Wales: 2297906
Registered office: Stag Gates House, 63/64 The Avenue, Southampton SO17 1XS

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: mysql_num_rows()

2011-02-22 Thread Pete Ford

On 22/02/11 05:40, Gary wrote:

Can someone tell me why this is not working?  I do not get an error message,
the results are called and echo'd to screen, the count does not work, I get
a 0 for a result...



$result = mysql_query(SELECT * FROM `counties` WHERE name = 'checked') or
die(mysql_error());

if ( isset($_POST['submit']) ) {
for($i=1; $i=$_POST['counties']; $i++) {
if ( isset($_POST[county$i] ) ) {
echo You have chosen . $_POST[county$i].br/;
 }
 }
}

$county_total=mysql_num_rows($result);

while($row = mysql_fetch_array($result))
{$i++;
 echo $row['name'];
}
$county_total=mysql_num_rows($result);
echo $county_total;

echo 'You Have '  .  $county_total  .  ' Counties ';

?


The first thing I see is that you do
  $county_total=mysql_num_rows($result)
twice. Now I'm not to sure, but it is possible that looping over 
mysql_fetch_array($result) moves an array pointer so the count is not valid 
after the operation... that's a long shot.


But since you are looping over the database records anyway, why not just count 
them as you go? Isn't $i the number of counties after all the looping?



--
Peter Ford, Developer phone: 01580 89 fax: 01580 893399
Justcroft International Ltd.  www.justcroft.com
Justcroft House, High Street, Staplehurst, Kent   TN12 0AH   United Kingdom
Registered in England and Wales: 2297906
Registered office: Stag Gates House, 63/64 The Avenue, Southampton SO17 1XS

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: mysql_num_rows()

2011-02-22 Thread Pete Ford

On 22/02/11 13:59, Gary wrote:

Pete Fordp...@justcroft.com  wrote in message
news:a4.c0.39221.b3ca3...@pb1.pair.com...

On 22/02/11 05:40, Gary wrote:

Can someone tell me why this is not working?  I do not get an error
message,
the results are called and echo'd to screen, the count does not work, I
get
a 0 for a result...



$result = mysql_query(SELECT * FROM `counties` WHERE name = 'checked')
or
die(mysql_error());

if ( isset($_POST['submit']) ) {
for($i=1; $i=$_POST['counties']; $i++) {
if ( isset($_POST[county$i] ) ) {
echo You have chosen . $_POST[county$i].br/;
  }
  }
}

$county_total=mysql_num_rows($result);

while($row = mysql_fetch_array($result))
{$i++;
  echo $row['name'];
}
$county_total=mysql_num_rows($result);
echo $county_total;

echo 'You Have '  .  $county_total  .  ' Counties ';

?


The first thing I see is that you do
   $county_total=mysql_num_rows($result)
twice. Now I'm not to sure, but it is possible that looping over
mysql_fetch_array($result) moves an array pointer so the count is not
valid after the operation... that's a long shot.

But since you are looping over the database records anyway, why not just
count them as you go? Isn't $i the number of counties after all the
looping?


--
Peter Ford, Developer phone: 01580 89 fax: 01580
893399
Justcroft International Ltd.
www.justcroft.com
Justcroft House, High Street, Staplehurst, Kent   TN12 0AH   United
Kingdom
Registered in England and Wales: 2297906
Registered office: Stag Gates House, 63/64 The Avenue, Southampton SO17
1XS



Peter

Thank you for your reply.

I did notice that I had the $county_total=mysql_num_rows($result) twice.  I
had moved and removed it, always getting either a 0 or 1 result.

I put up another test page with

$result = mysql_query(SELECT * FROM `counties` ) or die(mysql_error());

$tot=mysql_num_rows($result);
echo $tot;

?

And it worked fine.

I have tried count() as well as mysql_num_rows() but am getting the same
result.

Could you explain what you mean by count them as I go?

Again, Thank you for your reply.

Gary



__ Information from ESET Smart Security, version of virus signature 
database 5895 (20110222) __

The message was checked by ESET Smart Security.

http://www.eset.com






Well,

Lets go back to your original code and cut out the decoration:

$result = mysql_query(SELECT * FROM `counties` WHERE name = 'checked')
$county_total=mysql_num_rows($result);
while($row = mysql_fetch_array($result))
{
echo $row['name'];
}
echo $county_total;

That code should do pretty much what you want...

But, because you only show the number of records AFTER the loop, you could do:

$result = mysql_query(SELECT * FROM `counties` WHERE name = 'checked')
$county_total = 0;
while($row = mysql_fetch_array($result))
{
echo $row['name'];
$county_total++;
}
echo $county_total;





--
Peter Ford, Developer phone: 01580 89 fax: 01580 893399
Justcroft International Ltd.  www.justcroft.com
Justcroft House, High Street, Staplehurst, Kent   TN12 0AH   United Kingdom
Registered in England and Wales: 2297906
Registered office: Stag Gates House, 63/64 The Avenue, Southampton SO17 1XS

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] HTML errors

2011-01-13 Thread Pete Ford

On 12/01/11 14:13, Richard Quadling wrote:

On 12 January 2011 14:07, Steve Staplessstap...@mnsi.net  wrote:

On Wed, 2011-01-12 at 13:40 +, Richard Quadling wrote:

On 12 January 2011 13:20, Steve Staplessstap...@mnsi.net  wrote:

Jim,

Not to be a smart ass like Danial was (which was brilliantly written
though),  but you have your example formatted incorrectly.  You are
using commas instead of periods for concatenation, and it would have
thrown an error trying to run your example. :)

# corrected:
echo lia href=\index.php?page={$category}\{$replace}/a/li;

Steve Staples.


Steve,

The commas are not concatenation. They are separators for the echo construct.

I don't know the internals well enough, but ...

echo $a.$b.$c;

vs

echo $a, $b, $c;

On the surface, the first instance has to create a temporary variable
holding the results of the concatenation before passing it to the echo
construct.

In the second one, the string representations of each variable are
added to the output buffer in order with no need to create a temp var
first.

So, I think for large strings, using commas should be more efficient.

Richard.



Well... I have been learned.  I had no idea about doing it that way, I
apologize to you, Jim.

I guess my PHP-fu is not as strong as I had thought?

Thank you Richard for pointing out this to me,  I may end up using this
method from now on.  I have just always concatenated everything as a
force of habit.

Steve Staples.




I was never taught by nuns.



Eh? Oh I get it... (ugh!)
Surely PHP-fu is taught by monks?

--
Peter Ford, Developer phone: 01580 89 fax: 01580 893399
Justcroft International Ltd.  www.justcroft.com
Justcroft House, High Street, Staplehurst, Kent   TN12 0AH   United Kingdom
Registered in England and Wales: 2297906
Registered office: Stag Gates House, 63/64 The Avenue, Southampton SO17 1XS

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: HTML errors

2011-01-12 Thread Pete Ford

On 12/01/11 03:35, David McGlone wrote:

Hi Everyone, I'm having a problem validating some links I have in a foreach.
Here is my code:
  !DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.01 Transitional//EN
http://www.w3.org/TR/html4/loose.dtd;

my PHP code:
$categorys = array('home', 'services', 'gallery', 'about_us', 'contact_us',
'testimonials');
foreach($categorys as $category){
$replace = str_replace(_,  , $category);
echo lia href='index.php?page=$category'$replace/a/li;
}

Validator Error:
an attribute value must be a literal unless it contains only name characters

…omehome/a/lilia href=index.php?page=servicesservices/a/lilia
h…

I have tried various combinatons and different doctypes. I'm beginning to
wonder if this code is allowed at all.




All the other replies are talking nonsense (especially Daniel ;) !
There's no reason why HTML with single-quoted attributes isn't valid, so in 
principle your expected output of


a href='index.php?page=services'services/a

should be OK.

The real challenge is to understand why the code fragment you have presented is 
losing the single quotes: are you *sure* this is exactly what you have in your 
file (i.e. have you copied it to the posted message properly) ?


--
Peter Ford, Developer phone: 01580 89 fax: 01580 893399
Justcroft International Ltd.  www.justcroft.com
Justcroft House, High Street, Staplehurst, Kent   TN12 0AH   United Kingdom
Registered in England and Wales: 2297906
Registered office: Stag Gates House, 63/64 The Avenue, Southampton SO17 1XS

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: Form Processing

2010-11-30 Thread Pete Ford

On 29/11/10 23:54, Ron Piggott wrote:


I am unable to retrieve the value of $referral_1 from:

$new_email = mysql_escape_string ( $_POST['referral_$i'] );

why?

PHP while lopp to check if any of the fields were populated:



$i=1;
while ( $i= 5 ) {

 $new_email = mysql_escape_string ( $_POST['referral_$i'] );

 if ( strlen ( $new_email )  0 ) {

 }

}


The form itself:


form method=post action=”website”

p style=margin: 10px 50px 10px 50px;input type=text name=email maxlength=60 
class=referral_1 style=width: 400px;/p

p style=margin: 10px 50px 10px 50px;input type=text name=email maxlength=60 
class=referral_2 style=width: 400px;/p

p style=margin: 10px 50px 10px 50px;input type=text name=email maxlength=60 
class=referral_3 style=width: 400px;/p

p style=margin: 10px 50px 10px 50px;input type=text name=email maxlength=60 
class=referral_4 style=width: 400px;/p

p style=margin: 10px 50px 10px 50px;input type=text name=email maxlength=60 
class=referral_5 style=width: 400px;/p

p style=margin: 10px 50px 10px 50px;input type=submit name=submit value=Add New 
Referrals/p

/form


What am I doing wrong?

Ron

The Verse of the Day
“Encouragement from God’s Word”
http://www.TheVerseOfTheDay.info



The Daniels are on the right track, but not very clear:

First, the input elements all have the 'name' attribute set to 'email' and the 
'class' set to 'referral_1' etc. - I think you have that the wrong way round!


Second, using single quotes in the $_POST['referral_$i'] bit will not work (DPB 
is right there)  - use $_POST['referral_'.$i] or $_POST[referral_$i]





--
Peter Ford, Developer phone: 01580 89 fax: 01580 893399
Justcroft International Ltd.  www.justcroft.com
Justcroft House, High Street, Staplehurst, Kent   TN12 0AH   United Kingdom
Registered in England and Wales: 2297906
Registered office: Stag Gates House, 63/64 The Avenue, Southampton SO17 1XS

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: Xpath arguments in variable

2010-09-16 Thread Pete Ford

On 15/09/10 18:00, David Harkness wrote:

And let's not forget

$v = $row-xpath(//membernumber[. = \$MemberId\]);

The \ inside the string turns into a double-quote and using  to delimit
the string allows for variable substitution.



Oooh, I hate using backslashes - they always seem so untidy...
I have a pathological fear of sed scripts, too. :(


--
Peter Ford, Developer phone: 01580 89 fax: 01580 893399
Justcroft International Ltd.  www.justcroft.com
Justcroft House, High Street, Staplehurst, Kent   TN12 0AH   United Kingdom
Registered in England and Wales: 2297906
Registered office: Stag Gates House, 63/64 The Avenue, Southampton SO17 1XS

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: Xpath arguments in variable

2010-09-15 Thread Pete Ford
If you needed the double-quotes in the Xpath expression when the constant is 
used , then you probably need them in the variable version.


$v = $row-xpath('//membernumber[. = '.$MemberId.']');

That should put the double-quotes in for you...

On 15/09/10 09:33, Sridhar Pandurangiah wrote:


 Original Message 
Subject: Re: Xpath arguments in variable
From: php-gene...@garydjones.name (Gary)
To:
Date: Wed Sep 15 2010 13:34:11 GMT+0530 (IST)

Whats wrong with
$v = $row-xpath('//membernumber[. = ' . $MemberId . ']');
?

Am I not understanding what you are trying to ask?



I tried this but doesn't work. I guess the above statement is
concatenating the entire string and the substitution isn't happening

What I am trying to do is as follows
$MemberId = 'A192';
$v = $row-xpath('//membernumber[. = ' . $MemberId . ']');

The $MemberId should be substituted with A192 and then the xpath query
should be executed. The result should be that I locate the membernumber
XML element that has the value A912.

Best regards

Sridhar



Sridhar Pandurangiah wrote:

now I need to pass this value to XPath within a string variable say

$v = $row-xpath('//membernumber[. = $MemberId]');

But this doesnt work due to the quotes. What I intend PHP to do is to
substitute the value for $MemberId and then execute the XPath query. I
have grappled with it for a few days before posting this.


Whats wrong with $v = $row-xpath('//membernumber[. = ' . $MemberId .
']');
?

Am I not understanding what you are trying to ask?




--
Peter Ford, Developer phone: 01580 89 fax: 01580 893399
Justcroft International Ltd.  www.justcroft.com
Justcroft House, High Street, Staplehurst, Kent   TN12 0AH   United Kingdom
Registered in England and Wales: 2297906
Registered office: Stag Gates House, 63/64 The Avenue, Southampton SO17 1XS

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Standalone WebServer for PHP

2010-09-13 Thread Pete Ford

On 12/09/10 18:33, tedd wrote:

At 5:57 PM +0100 9/12/10, Ashley Sheridan wrote:

On Sun, 2010-09-12 at 12:55 -0400, tedd wrote:


Can a business have a server connected to the Internet but limit
access to just their employees? I don't mean a password protected
scheme, but rather the server being totally closed to the outside
world other than to their internal employees? Or is this something
that can only be provided by a LAN with no Internet connection?



Not entirely sure what you're asking, but could you maybe achieve
something like this with a WAN using a VPN?

Thanks,
Ash


Ash:

I'm sure this is an obvious question for many on this list, but I'm not
above showing my ignorance.

I guess what I am asking -- if a client wanted an application written
(in web languages) so that their employees could link all their
different computers together and share/use information using browsers,
is that possible using a server that is not connected to the Internet?

Look, I know that I can solve my clients problems by finding a host and
writing scripts to do what they want -- that's not a problem. But
everything I do is open to the world. Sure I can provide some level of
security, but nothing like the security that can be provided behind
closed and locked doors.

So, can I do what I do (i.e., programming) without having a host? Can I
install a local server at my clients location and interface all their
computers to use the server without them ever being connected to the
Internet?

Maybe I should ask my grandson. :-)

Cheers,

tedd




If the network is set up (as most business and home networks are these days) to 
use Network Address Translation (NAT) at the connection point to the world, then 
you shold be able to achieve this.
NAT is where you have an internal network using private addresses (often in the 
192.168.xxx.xxx range) but all outgoing traffic appears on the internet to come 
from one public address.


So you configure your web server to accept requests from only the internal 
addresses. With Apache you could do this on a per-directory basis, even, so the 
web server could have public content (visible to all client addresses) and then 
have private content in subdirectories which only accept clients on the internal 
network addresses.


There is a possible loophole due to IP address spoofing, but I suspect that your 
gateway device (firewall, ADSL or cable router that connects you to the world) 
will block those sort of clients.


--
Peter Ford, Developer phone: 01580 89 fax: 01580 893399
Justcroft International Ltd.  www.justcroft.com
Justcroft House, High Street, Staplehurst, Kent   TN12 0AH   United Kingdom
Registered in England and Wales: 2297906
Registered office: Stag Gates House, 63/64 The Avenue, Southampton SO17 1XS

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Trapping for PDF Type and file size in a UPLOAD form...

2010-07-30 Thread Pete Ford

On 29/07/10 19:10, tedd wrote:

At 9:50 AM -0700 7/29/10, Don Wieland wrote:

I am trying to create an UPLOAD form and need to figure a way to only
allow PDF files to be selected.


The short answer is you can't -- not from php. You can create a standard
form and upload it from there, but you don't have control over file type.

So you can't stop people from uploading anything to your site via the
form, but you can look at the document once it's there and inspect it.
Using a HEX Editor, I see that most pdf file have the first four bytes
as %PDF so you might check that before moving the file to somewhere
important. But that doesn't stop spoofing.

Other than that, I can't see any way to do it.

Cheers,

tedd


Second what tedd says, with a bit more: on a Linux backend system I run uploaded 
files through the 'file' command with a decent magic file to detect the file 
type. I also run every upload through a virus scanner (clamscan, for example) 
before I accept it.
If your PHP backend is windows then you might need to do some research to find a 
good file-type detection routine, although the virus scanning should be possible.


You certainly cannot trust the client side to do any checking. In any case, 
JavaScript doesn't (shouldn't) have access to the file you are trying to upload, 
so there's not much you can do there. You might achieve something client-side 
with Flash, or a Java uploader applet, I suppose.


Cheers
Pete

--
Peter Ford, Developer phone: 01580 89 fax: 01580 893399
Justcroft International Ltd.  www.justcroft.com
Justcroft House, High Street, Staplehurst, Kent   TN12 0AH   United Kingdom
Registered in England and Wales: 2297906
Registered office: Stag Gates House, 63/64 The Avenue, Southampton SO17 1XS

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Do you have some standard for defined the variable in program language?

2010-07-27 Thread Pete Ford

On 27/07/10 10:42, viraj wrote:

$firstName is the most readable.. for variables.

does anybody have negative thoughts on using the same naming format
for method/function and for class names?

i guess it's worth sharing! many thanks!

~viraj



I like to use $firstName, and function firstName(), but I would use class 
FirstName.

Somehow in my mind, classes are important enough to earn the initial capital 
letter.

--
Peter Ford, Developer phone: 01580 89 fax: 01580 893399
Justcroft International Ltd.  www.justcroft.com
Justcroft House, High Street, Staplehurst, Kent   TN12 0AH   United Kingdom
Registered in England and Wales: 2297906
Registered office: Stag Gates House, 63/64 The Avenue, Southampton SO17 1XS

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] storing files in database and retriving them

2010-07-27 Thread Pete Ford

On 27/07/10 14:16, Peter Lind wrote:

2010/7/27 Nilesh Govindarajanli...@itech7.com:

2010/7/27 Dušan Novakovićndu...@gmail.com:

Hello,

so when I'm sending the array to model it's like this:

$fp = fopen(INVOICE_PATH.date('Y-m-d').DS.$pdfName, r);
$pdfContent = array(
'file'  =
base64_encode(fread($fp,
filesize(INVOICE_PATH.date('Y-m-d').DS.$pdfName))),
'name'  =$pdfName,
'size'  =
filesize(INVOICE_PATH.date('Y-m-d').DS.$pdfName),
'type'  =
mime_content_type(INVOICE_PATH.date('Y-m-d').DS.$pdfName)
);
fclose($fp);

so the data in db are ok, and this type is application/pdf.

And when I'm getting data, I get the array like this:

$file = Array
(
[id] =  2
[file] =VBERi0xLjM...= here file is base64_encode()
[file_size] =  2204
[file_type] =  application/pdf
[file_name] =  2_file.pdf
)

Headers:

header(Content-length: .$file['file_size']);
header(Content-type: .$file['file_type']);
header(Content-Disposition: attachment; filename= .$file['file_name']);
echo base64_decode($file['file']);


So, mime looks ok, but still... not working :-(




--
mob: + 46 70 044 9432
web: http://novakovicdusan.com

Please consider the environment before printing this email.



Are you sure that you need Content-Disposition? Try removing that. I
think that's used only in emails (Correct me if I'm wrong).


You're wrong. Content-Disposition tells the browser how to handle the
content - in this case, the browser will download the file instead of
displaying it.

Regards
Peter



I think you need to be careful about quoting the file name in the 
Content-Disposition header: something like


header('Content-Disposition: attachment; filename='.$filename.'.xml');

seems to be the right quoting - the filename needs to be in double-quotes

--
Peter Ford, Developer phone: 01580 89 fax: 01580 893399
Justcroft International Ltd.  www.justcroft.com
Justcroft House, High Street, Staplehurst, Kent   TN12 0AH   United Kingdom
Registered in England and Wales: 2297906
Registered office: Stag Gates House, 63/64 The Avenue, Southampton SO17 1XS

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] How to alter the schema of a database to introduce newfeatures or change the current features

2010-07-15 Thread Pete Ford

On 15/07/10 06:03, Paul M Foster wrote:

On Wed, Jul 14, 2010 at 09:28:53PM -0700, Slith One wrote:


I'm developing an app using Zend Framwork using Git for version control.

What is the best approach for updating the schema and the database
when one of us makes an update to the db structure?

currently, we have to blow out the tables and recreate them manually
to reflect the new updates.


I'm probably being naive, but don't you have an ALTER TABLE sql
statement available to you?

Also, for what it's worth, I don't build tables manually (at the command
line or whatever). I always create a script which will build the tables
I need. If, for some crazy reason, I do have to restart from scratch,
it's a simple matter to alter that script and re-run it.

Paul



Scripting is the way to go for database changes: every time I have to make a 
schema change I write an SQL script to do the job, including any manipulation of 
data required. Then I make a copy of the real data and test the hell out of the 
change script before going live with it.
You can commit the database script to your source control at the time you commit 
the code changes, and then when you update the live system you run any new 
scripts at the same time.




--
Peter Ford, Developer phone: 01580 89 fax: 01580 893399
Justcroft International Ltd.  www.justcroft.com
Justcroft House, High Street, Staplehurst, Kent   TN12 0AH   United Kingdom
Registered in England and Wales: 2297906
Registered office: Stag Gates House, 63/64 The Avenue, Southampton SO17 1XS

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] How to alter the schema of a database to introducenewfeatures or change the current features

2010-07-15 Thread Pete Ford

On 15/07/10 09:14, Ashley Sheridan wrote:

ALTER TABLE is the way to go. If in doubt, look at the SQL phpMyAdmin
produces when you make the changes in there.

Thanks,
Ash
http://www.ashleysheridan.co.uk




Yeah, scripting ALTER TABLE commands ... :)

--
Peter Ford, Developer phone: 01580 89 fax: 01580 893399
Justcroft International Ltd.  www.justcroft.com
Justcroft House, High Street, Staplehurst, Kent   TN12 0AH   United Kingdom
Registered in England and Wales: 2297906
Registered office: Stag Gates House, 63/64 The Avenue, Southampton SO17 1XS

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Inner join woes... and sweet tea!

2010-07-05 Thread Pete Ford

On 05/07/10 14:38, Richard Quadling wrote:

On 5 July 2010 14:02, Jason Pruimli...@pruimphotography.com  wrote:

Hi everyone,

I'll admit right now that I'm still trying to wrestle with inner joins...


It is all about set theory. Imagine two circles, which overlap
(http://en.wikipedia.org/wiki/Venn_diagram#Example as an example).

For that example, simplistically, A contains me and my emu. B contains
my emu and the my deathwatch beetle.


SELECT * FROM A,B WHERE A.id = B.id (My emu)

SELECT * FROM A INNER JOIN B ON A.id = B.id (My emu)

SELECT * FROM A LEFT OUTER JOIN B ON A.id = B.id (Me and My emu)

SELECT * FROM A RIGHT OUTER JOIN B ON A.id = B.id (My emu and my
deathwatch beetle)

SELECT * FROM A FULL OUTER JOIN B ON A.id = B.id

returns in interesting set (essentially all things but 1 column for each table).

Me, null
My emu, my emu
null, My deathwatch beetle.

If you were using ISNULL ...

SELECT ISNULL(A.name, B.name) AS name FROM A FULL OUTER JOIN B ON A.id = B.id

would return all things

Me
My emu
My deathwatch beetle.


And, (I think), finally, an inversion of the inner join.


SELECT ISNULL(A.name, B.name) AS name FROM A FULL OUTER JOIN B ON A.id
= B.id WHERE A.id IS NULL OR B.id IS NULL

returns

Me
My deathwatch beetle.

All things except those 2 legged things that can fly.

I hope that helps.

Regards,

Richard.

P.S. I don't have an emu.


Clearly, or you'd know that they can't fly either...
:)

--
Peter Ford, Developer phone: 01580 89 fax: 01580 893399
Justcroft International Ltd.  www.justcroft.com
Justcroft House, High Street, Staplehurst, Kent   TN12 0AH   United Kingdom
Registered in England and Wales: 2297906
Registered office: Stag Gates House, 63/64 The Avenue, Southampton SO17 1XS

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: combo box validation

2010-06-09 Thread Pete Ford

On 07/06/10 18:49, David Mehler wrote:

Hello,
I've got a form with two combo boxes, one for the month one for the
day. Both are required. I've got code that checks the post submission
to ensure neither is empty. My problem is that if a user does not
select anything in the combo boxes January first is sent, this i don't
want. If they haven't selected anything i'd like that to show as an
error.
Thanks.
Dave.


It's not really php, but if you make the default option of each combo return an 
empty value then you can assume that the user didn't choose anything and flag 
the error:


Like:

select name='month'
option selected='selected' value=''Select One/option
option value='january'January/option
...
/select

You should find that if the empty option is selected the PHP will not receive a 
value in $_REQUEST['month'], or at least it will be something equivalent to NULL.


--
Peter Ford, Developer phone: 01580 89 fax: 01580 893399
Justcroft International Ltd.  www.justcroft.com
Justcroft House, High Street, Staplehurst, Kent   TN12 0AH   United Kingdom
Registered in England and Wales: 2297906
Registered office: Stag Gates House, 63/64 The Avenue, Southampton SO17 1XS

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] PHP Encoder like IonCube

2010-05-12 Thread Pete Ford

On 12/05/10 01:06, Ashley Sheridan wrote:

On Tue, 2010-05-11 at 16:50 -0700, Brian Dunning wrote:


Hi Shiplu -

I also have a product with similar requirements. I searched a LOT and was never 
able to find a free solution that I was satisfied with. Even a lot of the 
commercial solutions required some server-side runtime EXE or something be 
installed, and my customers are not tech savvy enough to get that going.

I ultimately settled on PHP Lockit, which is $29. It's a Windows program that 
you run to create an obfuscated version of your script. I'm very satisfied with 
the obfuscation, and it does not require any external runtime files or 
anything. Works like a charm, and I recommend it.

http://phplockit.com/

- Brian

On May 9, 2010, at 1:36 PM, shiplu wrote:


Is there any php encoder like IonCube ?
Looking for an opensource solution.
My main target is to deliver encoded php codes so that it can not be
re-engineered.








Does slightly limit you to the Windows platform though, which I always
think is a shame when using a language as open as PHP.

Thanks,
Ash
http://www.ashleysheridan.co.uk




Maybe it'll run under Wine?
I might just try that with a demo version...

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] PHP Encoder like IonCube

2010-05-12 Thread Pete Ford

On 12/05/10 10:48, Pete Ford wrote:

On 12/05/10 01:06, Ashley Sheridan wrote:

On Tue, 2010-05-11 at 16:50 -0700, Brian Dunning wrote:


Hi Shiplu -

I also have a product with similar requirements. I searched a LOT and
was never able to find a free solution that I was satisfied with.
Even a lot of the commercial solutions required some server-side
runtime EXE or something be installed, and my customers are not tech
savvy enough to get that going.

I ultimately settled on PHP Lockit, which is $29. It's a Windows
program that you run to create an obfuscated version of your script.
I'm very satisfied with the obfuscation, and it does not require any
external runtime files or anything. Works like a charm, and I
recommend it.

http://phplockit.com/

- Brian

On May 9, 2010, at 1:36 PM, shiplu wrote:


Is there any php encoder like IonCube ?
Looking for an opensource solution.
My main target is to deliver encoded php codes so that it can not be
re-engineered.








Does slightly limit you to the Windows platform though, which I always
think is a shame when using a language as open as PHP.

Thanks,
Ash
http://www.ashleysheridan.co.uk




Maybe it'll run under Wine?
I might just try that with a demo version...


Looks like it works fine under Wine, at least the demo does...



--
Peter Ford, Developer phone: 01580 89 fax: 01580 893399
Justcroft International Ltd.  www.justcroft.com
Justcroft House, High Street, Staplehurst, Kent   TN12 0AH   United Kingdom
Registered in England and Wales: 2297906
Registered office: Stag Gates House, 63/64 The Avenue, Southampton SO17 1XS

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] PHP Encoder like IonCube

2010-05-12 Thread Pete Ford

On 12/05/10 11:23, shiplu wrote:

Can you paste a sample encoded version of a php file on pastie.org?


Shiplu Mokadd.im
My talks, http://talk.cmyweb.net
Follow me, http://twitter.com/shiplu
SUST Programmers, http://groups.google.com/group/p2psust
Innovation distinguishes bet ... ... (ask Steve Jobs the rest)


OK, I just did the phpPgAdmin index.php page (just something public-domain I had 
lying around):


Here's the original: http://www.pastie.org/pastes/956801
and here's the encoded: http://www.pastie.org/pastes/956803

I haven't yet checked that the encoded version works!

--
Peter Ford, Developer phone: 01580 89 fax: 01580 893399
Justcroft International Ltd.  www.justcroft.com
Justcroft House, High Street, Staplehurst, Kent   TN12 0AH   United Kingdom
Registered in England and Wales: 2297906
Registered office: Stag Gates House, 63/64 The Avenue, Southampton SO17 1XS

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Converting floats to ints with intval

2010-05-06 Thread Pete Ford

On 06/05/10 11:52, Paul Waring wrote:

Ashley Sheridan wrote:

Why don't you store them as integer values and add in the decimal point
with something like sprintf() afterwards? Store the values as pence and
then you won't have any rounding problems.


If I was designing the system from scratch, that's what I'd do.
Unfortunately this is an add-on to a legacy system where currency values
are already stored as strings in the database (yes, not ideal I know,
but you have to work with what you've got).



Can you not just add up the floating point numbers and the round them with 
round() (http://www.php.net/manual/en/function.round.php)
Certainlay for consistent calculations I'd always use the float values for as 
long as possible...


Otherwise, why not multiply by 1000 before taking the intval, then at least you 
preserve the next decimal place.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Error handling strategies (db related)

2010-04-28 Thread Pete Ford

On 27/04/10 16:37, tedd wrote:

Error handling is almost an art form.



More like a black art - voodoo perhaps...

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: Weird problem with is_file()

2010-04-26 Thread Pete Ford

On 26/04/10 16:56, Michelle Konzack wrote:

Hello Peter,

Am 2010-04-26 09:28:28, hacktest Du folgendes herunter:

var_dump($isfile);

Don't make assumptions of what the value is, just check it.


Yes and grmpf!

The filename has a space at the end but it can not removed even using

 var_dump(str_replace(' ', '', $isfile);

if I put a '1' as search parameter all '1' are removed, but  WHY  can  I
not remove a space at the end?

Even if a do a

   mv the_file_not_recognized the_file_not_recognized\space

it is not detected... even if the var_dump() show me something like

   string(29) /tmp/the_file_not_recognized 

Simple to test

 exec(touch /tmp/the_file_not_recognized);
 $FILE=shell_exec(ls /tmp/the_file_not_* |head -n1);
 var_dump($FILE);
 echo br;
 var_dump(str_replace(' ', '', $FILE);

Thanks, Greetings and nice Day/Evening
 Michelle Konzack
 Systemadministrator



Is it possible that the space is a new-line (or a carriage-return) ?

What happens if you replace
   str_replace(' ', '', $FILE)
with
   preg_replace('/\s+$/','',$FILE);

?


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] PHP GUI library/package

2010-03-31 Thread Pete Ford

Hi All,

I have a web project built in PHP which we want to break out part of into a 
stand-alone GUI program. The architecture is fine - display nicely separated 
from logic, so coding is not a problem.
What I can't work out is what to use for the GUI part. I looked at phpqt but I 
can't (yet) get that to build on my Linux dev system, let alone code an 
interface with it. I was also looking a PHP-GTK2, but I'm not sure how 
cross-platform it would be - this should run on Windows and Macs as well as Linux...


Anyone made a GUI PHP application like this, with one of the major toolkits?

Cheers
Pete

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] PHP GUI library/package

2010-03-31 Thread Pete Ford

On 31/03/10 15:30, Ashley Sheridan wrote:

On Wed, 2010-03-31 at 15:30 +0100, Pete Ford wrote:


Hi All,

I have a web project built in PHP which we want to break out part of into a
stand-alone GUI program. The architecture is fine - display nicely separated
from logic, so coding is not a problem.
What I can't work out is what to use for the GUI part. I looked at phpqt but I
can't (yet) get that to build on my Linux dev system, let alone code an
interface with it. I was also looking a PHP-GTK2, but I'm not sure how
cross-platform it would be - this should run on Windows and Macs as well as 
Linux...

Anyone made a GUI PHP application like this, with one of the major toolkits?

Cheers
Pete




I think as far as compatibility goes, QT is your best bet. What is
preventing you from getting that build onto your dev system?

Thanks,
Ash
http://www.ashleysheridan.co.uk




Two pints at lunchtime, mainly :)

I need to focus on it a bit better: I'll have another look and ask again if I 
still have trouble.


Cheers
Pete

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] PHP GUI library/package

2010-03-31 Thread Pete Ford

On 31/03/10 15:30, Ashley Sheridan wrote:

On Wed, 2010-03-31 at 15:30 +0100, Pete Ford wrote:


Hi All,

I have a web project built in PHP which we want to break out part of into
a stand-alone GUI program. The architecture is fine - display nicely
separated from logic, so coding is not a problem. What I can't work out is
what to use for the GUI part. I looked at phpqt but I can't (yet) get that
to build on my Linux dev system, let alone code an interface with it. I was
also looking a PHP-GTK2, but I'm not sure how cross-platform it would be -
this should run on Windows and Macs as well as Linux...

Anyone made a GUI PHP application like this, with one of the major
toolkits?

Cheers Pete




I think as far as compatibility goes, QT is your best bet. What is preventing
you from getting that build onto your dev system?

Thanks, Ash http://www.ashleysheridan.co.uk





Not all down to the beer.
I unpacked the php-qt-0.9.tar.gz and made a build directory in there, ran cmake
(which seemed to go OK), but make fails at
[  8%] Building CXX object smoke/qt/CMakeFiles/smokeqt.dir/x_2.o

with a bunch of errors like

/home/pete/phpqt/build/smoke/qt/x_2.cpp: In static member function ‘static void
x_QAccessibleBridgeFactoryInterface::x_0(Smoke::StackItem*)’:
/home/pete/phpqt/build/smoke/qt/x_2.cpp:167: error: cannot allocate an object of
abstract type ‘x_QAccessibleBridgeFactoryInterface’
/home/pete/phpqt/build/smoke/qt/x_2.cpp:163: note:   because the following
virtual functions are pure within ‘x_QAccessibleBridgeFactoryInterface’:
/usr/include/QtCore/qfactoryinterface.h:53: note:   virtual QStringList
QFactoryInterface::keys() const


I'm building on an OpenSuSE 11.1 system, but looking around it seems that Fedora 
12 has a php-qt package, so I'm putting together a VM to try it on there...


If you have any light to shed, then let me know. The php-qt mailing list seems a 
bit empty at the moment...


Cheers
Pete

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: PHP in HTML code

2010-03-18 Thread Pete Ford

On 17/03/10 18:59, Tommy Pham wrote:

On Wed, Mar 17, 2010 at 11:01 AM, Rene Veermanrene7...@gmail.com  wrote:

hmm.. seems easier to me to push a filetree of .php's with?= through
the str_replace(), than it is to get all the?= writers to comply
with your wishes, which may not apply to their situation ;-)

On Wed, Mar 17, 2010 at 5:14 PM, teddtedd.sperl...@gmail.com  wrote:

At 8:55 PM -0400 3/16/10, Adam Richardson wrote:


That said, I'm not taking exception with those who don't use the short
tag, only with those who say I shouldn't.


Exception or not, it's still your choice and using short tags can cause
problems.

My view, why create problems when there is a solution? Forcing the issue is
a bit like I'm going to do it my way regardless! I've traveled that path
too many times in my life. Sometimes it's easier to take the path most
traveled.

Cheers,

ted
--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




http://www.php.net/manual/en/language.basic-syntax.phpmode.php

There are four different pairs of opening and closing tags which can
be used in PHP. Two of those,?php ?  andscript language=php
/script, are always available. The other two are short tags and ASP
style tags, and can be turned on and off from the php.ini
configuration file. As such, while some people find short tags and ASP
style tags convenient, they are less portable, and generally not
recommended. 


But the implication there is that they are *only* non-portable *because* they 
can be switched off - there's no other strong reason. Before anyone jumps in 
with XML / XHTML arguments again, those issues are fairly rare and very easily 
worked around. My projects tend to use XHTML doctype because it makes IE7/8 
behave more predictably without a ?xml ? block, and I always use short tags 
for ?= because the alternative is so ugly! In the rare cases where I generate 
XML from a PHP script, there are workarounds for the ? problem.

I do tend to use ?php for blocks of code - so I guess I'm in the middle camp 
here.
I also write code to be hosted on dedicated systems that I have full control 
over, so php.ini settings are always in my control (so far...)


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: Enforce a constant in a class.

2010-01-25 Thread Pete Ford

Richard Quadling wrote:

2010/1/22 Pete Ford p...@justcroft.com:

IMHO, a constant is not the correct beastie in this case - if you want it to
be different depending on the implementation then it ain't a constant!

You should probably have protected static variables in the interface, and
use the implementation's constructor to set the implementation-specific
value (or override the default)

interface SetKillSwitch
{
   protected static $isSet = TRUE;
   protected static $notes;
   protected static $date = '2010-01-22T11:23:32+';
}

class KilledClass implements SetKillSwitch
{
   public function __construct()
   {
   self::$isSet = FALSE;
   self::$date = '2010-01-21T09:30:00+';
   self::$notes = Test;
   }
}

Cheers
Pete Ford


And of course, Fatal error: Interfaces may not include member variables.





Ooops, sorry :)

I tend to end up using abstract base classes rather than interfaces for 
that sort of reason...


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: Enforce a constant in a class.

2010-01-22 Thread Pete Ford

Richard Quadling wrote:

Hello,

One of the aspects of an interface is to enforce a public view of a
class (as I see it).

Within PHP, interfaces are allowed to have constants, but you cannot
override them in a class implementing that interface.

This seems wrong.

The interface shouldn't define the value, just like it doesn't define
the content of the method, it only defines its existence and requires
that a class implementing the interface accurately matches the
interface.

Is there a reason for this behaviour?



_OR_

How do I enforce the presence of a constant in a class?

?php
interface SetKillSwitch {
const KILL_SWITCH_SET = True;

// Produces an error as no definition exists.
// const KILL_SWITCH_NOTES;

// Cannot override in any class implementing this interface.
const KILL_SWITCH_DATE = '2010-01-22T11:23:32+';
}

class KilledClass implements SetKillSwitch {
// Cannot override as defined in interface SetKillSwitch.
// const KILL_SWITCH_DATE = '2010-01-22T11:23:32+';
}
?

I want to enforce that any class implementing SetKillSwitch also has a
const KILL_SWITCH_DATE and a const KILL_SWITCH_NOTES.

I have to use reflection to see if the constant exists and throw an
exception when it doesn't.

The interface should only say that x, y and z must exist, not the
values of x, y and z.

Regards,

Richard.

--
-
Richard Quadling
Standing on the shoulders of some very clever giants!
EE : http://www.experts-exchange.com/M_248814.html
EE4Free : http://www.experts-exchange.com/becomeAnExpert.jsp
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498r=213474731
ZOPA : http://uk.zopa.com/member/RQuadling


IMHO, a constant is not the correct beastie in this case - if you want 
it to be different depending on the implementation then it ain't a constant!


You should probably have protected static variables in the interface, 
and use the implementation's constructor to set the 
implementation-specific value (or override the default)


interface SetKillSwitch
{
protected static $isSet = TRUE;
protected static $notes;
protected static $date = '2010-01-22T11:23:32+';
}

class KilledClass implements SetKillSwitch
{
public function __construct()
{
self::$isSet = FALSE;
self::$date = '2010-01-21T09:30:00+';
self::$notes = Test;
}
}

Cheers
Pete Ford

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: how to retrieve a dom from innerHTML......

2010-01-20 Thread Pete Ford

I am on the top of the world! Borlange University wrote:

hello, i can obnot retrieve a select ject from div innerHTML.
what i want to do is that when a page is loaded, first selector,say #1,
would be shown in the first div by sending a request.then i choose one
option from #1, fire change event of #1, the second selector #2 will be
shown in div two, then choose option from #2 .blabla..

but the problem is when selector #1 was loaded, the object #1 could not be
obtained.
codes:

window.addEvent('domready', function() {

 var option=1;

 var result = new Request({
  
url:'getInfo_gx.php'https://mail.google.com/mail/html/compose/static_files/'getInfo_gx.php'
,
  method:'get',
  onSuccess:function(response)
  {
   if(option==1) $('list_sch').innerHTML = response; //response =
select id='sch_list...';
   else if(option==2) $('list_gg').innerHTML = response;
   else $('list_gx').innerHTML = response;

  }
 });


result.send('type=1');// page loaded,sending a request.


 $('list_sch').innerHTML = select id='sch_list'option
value='123'123312/option/select;


 if($('sch_list')) // heres the problem... object can not
be obtained.
 {
   $('sch_list').addEvent('change',function(){   // events
can not be  fired
   option=2;
   result.send('type=2'+'sch='+$('sch_list').value.replace('+','%2B'));
  });
 }

});



You probably ought to ask a Javascript forum about javascript problems...

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] strtotime - assumptions about default formatting of dates

2010-01-04 Thread Pete Ford

On 24/12/09 16:59, Bastien Koert wrote:

On Thu, Dec 24, 2009 at 9:12 AM, teddtedd.sperl...@gmail.com  wrote:

At 10:20 PM +1000 12/24/09, Angus Mann wrote:


Hi all. I need to allow users to enter dates and times, and for a while
now I've been forcing them to use javascript date/time pickers so I can be
absolutely sure the formatting is correct.

Some users are requesting to be able to type the entries themselves so
I've decided to allow this.

I'm in Australia, and the standard formatting of dates here is DD/MM/
or DD-MM-

I recognize this is different to what seems to happen in the US, where it
is MM/DD/ or MM-DD-

When I process an entered date using strtotime() it seems to work fine.

But of course I am concerned when dates like January 2 come up.

I find that 2/1/2009 is interpreted as January 2, 2009 on my installation,
which is Windows 7 with location set to Australia.

But can I be sure that all installations of PHP, perhaps in different
countries and on different operating systems will interpret dates the same?

I can't find much mention of this question online or in the manual.

Any help much appreciated.
Angus


Angus:

You are running into a problem that cannot be solved by allowing the user to
do whatever they want. As you realize, if I enter 01-02-09 you don't know if
I mean January 2, 2009 or February 1, 2009 and there is no way to figure out
what I meant.

The solution is simply to use the htmloption  and give the user that way
to enter month and day.

I would set it to day-month-year and let US visitors live with it for I
personally think that's a better format.

Cheers and Merry Christmas.

tedd


--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




I would agree with tedd. Use a JS calendar widget (requires js) or use
three select boxes for mm , dd and year



I developed my little text input AJAX (see earlier post) to work around the fact 
that a LOT of users I encountered were cheesed off by JS calendar widgets, 
especially when the date to be entered was a long way from the current date 
(such as a date of birth). I tried implementing some scroll-wheel events to 
speed up year selection on one of these but it was tricky to get cross-browser 
support.


Drop-downs are a pain when you have to scroll back 40+ years to find the right 
one and are implicitly limited by how far back and forward the designer expects 
to need, and then you have the problem of validating the days and months (which, 
to be fair, is a pretty simple javascript task)


I suspect that with a bit of thought I could put together a Javascript date 
validator that parsed most possible inputs and produced a sensible 
interpretation of them, but I was lazy and had AJAX machinery set up already in 
my project.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: strtotime - assumptions about default formatting of dates

2009-12-24 Thread Pete Ford

On 24/12/09 12:20, Angus Mann wrote:

Hi all. I need to allow users to enter dates and times, and for a while now 
I've been forcing them to use javascript date/time pickers so I can be 
absolutely sure the formatting is correct.

Some users are requesting to be able to type the entries themselves so I've 
decided to allow this.

I'm in Australia, and the standard formatting of dates here is DD/MM/ or 
DD-MM-

I recognize this is different to what seems to happen in the US, where it is 
MM/DD/ or MM-DD-

When I process an entered date using strtotime() it seems to work fine.

But of course I am concerned when dates like January 2 come up.

I find that 2/1/2009 is interpreted as January 2, 2009 on my installation, 
which is Windows 7 with location set to Australia.

But can I be sure that all installations of PHP, perhaps in different countries 
and on different operating systems will interpret dates the same?

I can't find much mention of this question online or in the manual.

Any help much appreciated.
Angus



I wrote a little AJAX gadget which sent the string typed to a PHP backend which 
parsed it using strtotime and then formatting it out again as something 
unamiguous (like 2 January 2009). Then every time the date entry field is 
changed by the user (with an onKeyUp event), this AJAX call is triggered and 
displays the unambiguous form next to the input box, so users can see how their 
entry is being interpreted.

Of course, there's some overhead in the AJAX calls, and it requires JavaScript.

If you wanted to do without JavaScript you could do a similar parse-format 
sequence when the form is submitted and show a confirmation page with your 
server's interpretation of the date.


Cheers
Pete

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php