[PHP] Accessing the 'media' attribute in php

2008-12-02 Thread Clancy
Is it possible to access the 'media' attribute from php, so (for
example) you can tailor a page for printing?


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



Re: [PHP] Accessing the 'media' attribute in php

2008-12-02 Thread Clancy
Oh? 

Unfortunately I have had great difficulty trying to find out how
things really work, as all the books I have seen are recipe books,
which tell you how to achieve particular results, but not what is
going on behind the scenes.  I had assumed that when you hit the
'print' button the browser sent a new request to the server, with a
different set of parameters, but I gather from your reply that the
browser issues the new (printer) page without reference to the server.
Is this what actually happens?

If so I fear I will have to work out how to achieve the results I want
with CSS styles.  It would have been far simpler if I could have done
it in php.

Thank you for your help.

On Wed, 3 Dec 2008 14:34:20 +1300, [EMAIL PROTECTED] ("German Geek")
wrote:

>PHP is a server side language...
>
>On Wed, Dec 3, 2008 at 2:16 PM, Clancy <[EMAIL PROTECTED]> wrote:
>
>> Is it possible to access the 'media' attribute from php, so (for
>> example) you can tailor a page for printing?
>>
>>
>> --
>> 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



Re: [PHP] Accessing the 'media' attribute in php

2008-12-02 Thread Clancy
On Wed, 3 Dec 2008 15:28:17 +1300, [EMAIL PROTECTED] ("German Geek")
wrote:

>You can do things on the client side with Javascript ;) Sorry, what was the
>result you are after?

I have enough trouble getting my rather ancient brain around PHP, and
was hoping that I could avoid getting involved with JavaScript.
However it seems that it, or CSS, are the only possibilities for this
case.

Bother!

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



Re: [PHP] Accessing the 'media' attribute in php

2008-12-03 Thread Clancy
On Wed, 03 Dec 2008 08:15:14 +, [EMAIL PROTECTED] (Ashley
Sheridan) wrote:

>Go with what Yeti said. The browser will automatically pick the right
>stylesheet when the user presses the print button or you issue a
>window.print() from Javascript. Whatever you do, don't have a separate
>page for "print view". This is one of those things that some bright
>spark thought to do on a site at work, and the site in question was
>already a couple hundred HTML pages, so he effectively doubled that
>figure. It makes your work harder in the long run if you need to update
>it at any time, and with the media="print" attribute set for the extra
>stylesheet, it's automatically selected anyways.
>
>On an aside, Opera has a neat option that lets you select from all the
>stylesheets a page has available, which will make it easier when you're
>developing the stylesheet rather than having to keep clicking print
>preview in your browser!

Thank you to everyone who has replied on this. While there are
reasonably good books on the individual tools (PHP, JavaScript, etc)
very few go into how they all interact, and this was the subject of my
confusion.  Maciek's succinct description has made it clear why my
original request could never be implemented, so I will have to use CSS
to achieve the results I want.

This is not THAT bad, but CSS was clearly not designed by a
programmer, and to my mind seems to have a very convoluted logic, so I
prefer to avoid using it if I can.

And thank you for the tip about Opera. That feature sounds as if it
could be very useful!

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



Re: [PHP] Poll of sorts: Javascript Form validation or PHP

2008-12-05 Thread Clancy
On Fri, 05 Dec 2008 20:24:07 +, [EMAIL PROTECTED] (Ashley
Sheridan) wrote:

>On Fri, 2008-12-05 at 15:16 -0500, Bastien Koert wrote:
>> On Fri, Dec 5, 2008 at 3:18 PM, Ashley Sheridan <[EMAIL PROTECTED]>wrote:
>> 
>> > On Fri, 2008-12-05 at 12:08 -0800, Yeti wrote:
>> > > Java Script should always be an option, unless you write the
>> > > validation for yourself or people you personally know only.
>> > >
>> > JavaScript is client-side, ergo untrusted. Javascript can be nice as an
>> > addition, but only that.
>> >
>> >
>> > Ash
>> > www.ashleysheridan.co.uk
>> >
>> >
>> > --
>> > PHP General Mailing List (http://www.php.net/)
>> > To unsubscribe, visit: http://www.php.net/unsub.php
>> >
>> >
>> Never trust the user, always validate on the server
>> 
>
>Or, never trust the user, the user is stupid ;)

Or, worse, malicious!

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



[PHP] More microptimisation (Was Re: [PHP] Variable as an index)

2008-12-22 Thread Clancy
On Mon, 22 Dec 2008 10:20:09 +1100, dmag...@gmail.com (Chris) wrote:

>I'd call this a micro-optimization. If changing this causes that much of 
>a difference in your script, wow - you're way ahead of the rest of us.

Schlossnagle (in "Advanced PHP Programming") advises:

$i = 0; while ($i < $j)
{

++$i;
}

rather than:

$i = 0; while ($i < $j)
{
...
$i++;
}

as the former apparently uses less memory references.  However I find it very 
hard to
believe that the difference would ever show up in the real world.


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



Re: [PHP] More microptimisation (Was Re: [PHP] Variable as an index)

2008-12-23 Thread Clancy
On Mon, 22 Dec 2008 22:40:58 -0800, larstor...@gmail.com ("Lars Torben Wilson") 
wrote:

>Well, in all fairness, it *is* faster--but you'll only notice the
>difference in extremely tight and long-running loops (try it ;) ). As
>long as you know why you're using it and what the side effects are, it
>would be fine. But as an optimization tool, I'd agree that it's pretty
>much pointless.
>
>It's good to remember the Rules of Optimization:
>
>#1) Don't.
>#2) (For experts only) Don't do it yet.

I like that!


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



[PHP] Re: Assignment (Was Re: [PHP] More microptimisation (Was Re: [PHP] Variable as an index)

2008-12-23 Thread Clancy
On Tue, 23 Dec 2008 10:25:13 -0500, tedd.sperl...@gmail.com (tedd) wrote:

>At 9:10 AM +1100 12/23/08, Clancy wrote:
>>Schlossnagle (in "Advanced PHP Programming") advises:
>>
>>$i = 0; while ($i < $j)
>>  {
>>  
>>  ++$i;
>>  }
>>
>>rather than:
>>
>>$i = 0; while ($i < $j)
>>  {
>>  ...
>>  $i++;
>>  }
>>
>>as the former apparently uses less memory references.  However I 
>>find it very hard to
>
>Two things:
>
>1. One statement, one line.
>2. The code between the two examples is different; produces different 
>results; and thus is rather pointless in making a definitive 
>comparison.
>
>Assignment, demonstrate a correct way to test ++i vs i++.
>
>Cheers,
>
>tedd

Spoken like a true demagogue -- nitpicking about trivial points of style, but 
displaying
total ignorance of elementary rules of programming. 

One of the things I like about Schlossnagle's book is that he gives commonsense 
advice.
Specifically he advises against obsessing about other people's style rules, but 
suggests
that you choose a style that you like, and use it consistently.

And as the examples are written they do exactly the same thing; they each go 
through the
empty loop $j times. I had rashly assumed that anyone reading this discussion 
group would
understand that they were shorthand for something like the following:

$i = 0; while ($i < $j)
{
If ($a[$i])
{
[ some operation involving $i]
}
$i++;
}

$i cannot be incremented at the start as it is used inside the conditional 
expression, nor
can it be implemented inside the expression or you would get an infinite loop 
the first
time you missed it, so it has to be incremented at the end of the loop, and it 
is
immaterial whether you choose ++$i; or $i++;

Clancy

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



[PHP] Mirroring/caching PHP webpages.

2009-01-15 Thread Clancy
For some time I have had feedback pages on several of my websites based on the 
example
given by David Powers in chapter 6 of "PHP for Dreamweaver 8". These worked 
fine for some
years, but some months ago someone started stuffing pornographic advertisements 
into them.

A few weeks ago I got fed up with these messages, and devised a very simple 
filter to
reject them  (I won't explain how this works, because if I did the perpetrators 
could
immediately change their technique to defeat it).   If the content was 
acceptable I
handled the message in the normal way, but otherwise I deleted the contents, 
and forwarded
the message to a different address with the title "rubbish from XXX website".  
This worked
well, but then I decided I didn't need to know anything about this stuff at 
all, so I
modified the logic so that if the message is unacceptable it is simply dumped, 
but the
sender is still shown the normal "Thank you for your feedback" message. This 
way the
sender cannot tell whether or not his message has actually been sent, and so he 
cannot
experiment to try to break the filter.

Now if I try to send myself bad messages they simply disappear without trace, 
as expected,
but  I am still getting one or two messages a day sent with the version 1 
(censored)
logic.  I have changed the messages in my new version, and verified that the 
old messages
do not appear anywhere on my hard disk, and that there is only the new version 
of the
feedback procedure on my server.  

The only explanation I can see is that someone has somehow managed to cache or 
mirror the
version 1 logic, and is still dutifully stuffing pornography into it. As it is 
my
understanding that the PHP code which handles the processing is inaccessible to 
the user,
I cannot understand how this could have been done.  Does anyone have any 
suggestions?


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



Re: [PHP] Mirroring/caching PHP webpages.

2009-01-17 Thread Clancy
On Fri, 16 Jan 2009 00:51:58 -0500, pa...@quillandmouse.com (Paul M Foster) 
wrote:

>On Fri, Jan 16, 2009 at 11:57:24AM +1100, Clancy wrote:
.
>> The only explanation I can see is that someone has somehow managed to
>> cache or mirror the
>> version 1 logic, and is still dutifully stuffing pornography into it. As
>> it is my
>> understanding that the PHP code which handles the processing is inaccessible
>> to the user,
>> I cannot understand how this could have been done.  Does anyone have
>> any suggestions?
>> 
>
>If Google can spider and read your site, why can't someone else? I've
>had similar things happen. Any program that uses the HTTP protocol to
>fetch your site will only get the page as rendered by the server-- sans
>PHP. But I can imagine someone else programming something to snag the
>page a different way-- *with* PHP.
>
>But actually, they don't even have to be that sophisticated. All they
>have to do is submit a message to your form the first time, note the
>variables and their characteristics, and then resubmit that same type of
>content later using the same variable names and characteristics.
>
>Here's something you might do:
>
>1) Rename the page in question. That way their submission won't
>piggyback on your existing PHP code. 
>
>2) Change all the variable names in the file.
>
>Chances are, they're just submitting an HTTP request with the proper
>POST/GET variables so your page processes it as though it were being
>accessed "live". But if they try to submit this same content to a form
>that goes nowhere, Apache will just give them a 404 error.
>Alternatively, if you change your variable names and they submit to your
>existing form, your PHP can simply ignore it.
>
>Also, you might try CAPTCHA (look it up). It tries to weed out human
>from non-human surfers. You've probably got a 'bot submitting to you, so
>this might help.

The page has text boxes for the name and e-mail address, a text area for the 
message, and
a submit button. When the user hits the submit button the original code 
evaluates all the
inputs, and either re-issued the page if it didn't like them, or transmits the 
message,
with the title "Feedback from XXX website". If the message is transmitted 
successfully the
user is then shown a "Thank you for your feedback" page.

In version 1 of the modification if the message passed the initial test I then 
submitted
it to a second test. If it failed this, I replaced the message with 
"[Censored]", and sent
it to an alternative address, with the title "Rubbish from XXX website" but 
showed the
same "Thank you" page. I did this just so that if I accidentally rejected 
something from
someone I knew, I could email them and ask them to send the message again.

After a few days I decided I didn't need to know anything about these bogus 
messages, so I
developed version 2 of the modification. This is the same as version 1, except 
that it
uses a different title and replacement message (even though they are no longer 
used), and
simply discards the message, but again shows the normal "Thank you" page.

With either modification there is nothing to tell the sender that their message 
has been
rejected, and, as I never reply to such messages, no way for them to find out 
whether or
not I actually received their message. Whenever I try to send myself a bad 
message nothing
happens, so that version 2 appears to have been implemented.  I do not get any 
uncensored
messages of this type now, so the rejection algorithm is satisfactory, but I'm 
still
getting one or two messages handled by version 1 each day.

I cannot see how this could happen unless someone has somehow managed to trap 
the version
1 PHP code (or, just conceivably, my provider switches to a backup containing 
an old code
at some stage in a maintenance cycle). 

I raised this matter out of interest, because I cannot explain what is 
happening, but my
actual problem is very slight, and as I'm in the process of converting this 
website from
an HTML design with hundreds of individual pages to a PHP-based design I will 
wait till I
have completed the conversion before I do any more investigation.

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



[PHP] Hidden costs of PHP arrays?

2009-01-27 Thread Clancy
PHP arrays permit extremely concise programming; for example if I have all my 
contacts in
an array $contacts, I can write:

$my_phone_no = $contacts['clancy']['phone'];

However it is clear that there must be a lot going on behind the scenes to 
achieve this
simple result, as it requires some sort of search procedure.

Is it possible to give any indication of the overheads and memory costs that 
are involved
in such a statement, and of how well the search procedure is implemented?

Also what the relative virtues of defining the same set of fields for every 
contact, as
against either defining only the fields which actually hold values, as in the 
following
examples?

a:
$contacts['clancy']['home_address'] = 'jkjkjk';
$contacts['clancy']['home_phone'] = 0123 4567;
$contacts['clancy'][' office_address''] = '';
$contacts['clancy']['office_phone'] = '';
$contacts['joe']['home_address'] = '';
$contacts['joe']['home_phone'] = '';
$contacts['joe']['office_address'] = 'jsfvkl';
$contacts['joe']['office_phone'] = 'jsfvkl';

b;
$contacts['clancy']['home_phone'] = 0123 4567;
$contacts['clancy']['home_address'] = 'jkjkjk';
$contacts['joe']['office_address'] = 'jsfvkl';
$contacts['joe']['office_phone'] = 'jsfvkl';

And is there any advantage in always assigning the keys in the same order?


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



[PHP] Re: Hidden costs of PHP arrays?

2009-01-29 Thread Clancy
On Wed, 28 Jan 2009 00:50:18 +, nrix...@gmail.com (Nathan Rixham) wrote:

>Clancy wrote:
>> Also what the relative virtues of defining the same set of fields for every 
>> contact, as
>> against either defining only the fields which actually hold values, as in 
>> the following
>> examples?
>> 
>> a:
>> $contacts['clancy']['home_address'] = 'jkjkjk';
>> $contacts['clancy']['home_phone'] = 0123 4567;
>> $contacts['clancy'][' office_address''] = '';
>> $contacts['clancy']['office_phone'] = '';
>> $contacts['joe']['home_address'] = '';
>> $contacts['joe']['home_phone'] = '';
>> $contacts['joe']['office_address'] = 'jsfvkl';
>> $contacts['joe']['office_phone'] = 'jsfvkl';
>> 
>> b;
>> $contacts['clancy']['home_phone'] = 0123 4567;
>> $contacts['clancy']['home_address'] = 'jkjkjk';
>> $contacts['joe']['office_address'] = 'jsfvkl';
>> $contacts['joe']['office_phone'] = 'jsfvkl';
>> 
>
Thanks to everyone who has commented. 

>if you go for option b; you're going to have do a vast amount of isset() 
>checks in a for loop and all kinds of fancy business logic for
>
>$contacts['clancy']['home_phone'] = 0123 4567;
>vs
>$contacts['clancy']['home_phone'] = '';
>vs
>'home_phone' not set
>

This question is far less clear-cut than you might assume. The data is actually 
stored as
a text document, with a separate line for each piece of information. To 
minimise the file
length blank fields are simply omitted. When I load the file into memory it is 
much
simpler to enter only the fields which are actually specified. As there are 
~600 entries
this presumably gives a significant saving in loading time and in memory.

However if I take this approach I then have to add an "if(isset( ...))" test 
before I read
each field when I'm trying to access a specific entry. This would only increase 
the memory
usage by a very small amount, and would have a negligible effect on timing.

So if I fill in all the entries when I load the file it will increase the 
loading times
slightly, and use slightly more memory.  On the other hand it will save me from 
having to
think about it whenever I access a variable.  The question really comes down to 
whether
the saving in memory if I don't load the empty variables is worth the extra 
programming
hassle when I write new procedures for accessing an entry.

>so one would guess that code would far outweigh any tiny speed gain from 
>dropping the additional items in the array.
>
>on another note; php has been stable and speedy now for a very long 
>time, some bit's like the reflection api could be speeded up a little 
>bit as demand grows, but certainly all scalars and compound types have 
>been tested and optimized to hell and back (afaik).
>
One could reasonably hope that the same could be said for every part of the 
programming
chain, but it is one of the ironies of modern computing that computers get 
faster and
faster, memory gets cheaper and cheaper, programming appears to get simpler and 
simpler,
yet the programs get slower and slower. I have a fairly modern (maybe 2yo) 
computer, and
use XP professional 5.1. Not long ago I switched to Office 2007 12.0, and when 
I did so I
was appalled to discover that if I had a document loaded into Word, and hit 
Ctrl A, I
could watch the highlighting scroll down the screen!

As a former assembly language programmer I have some idea of the vast amount of 
thumb
twiddling which is going on behind-the-scenes when I make some apparently 
simple request
like the one to get my phone number. Undoubtedly most of this occurs in the 
murky depths
of the operating system, but if there were any simple way to avoid adding to it
unnecessarily it would be nice to know about it.

>you can test this all you're self, simply populate an array with say 
>1000 random other arrays of data with 10 keys each, stick it in a for 
>loop and time several times, then do the same for an array as above but 
>with subarrays of only 5 keys; see if you can spot any significant 
>difference. [then compare to say a single database select, or an 
>execution of a small script.]
>
>another way of putting it; I'm 99% sure that nobodies code is perfectly 
>optimised enough by itself to notice any performance hits from php; 
>quite sure you could make far bigger gains by optimising you're own code 
>first :p
>
>regards! 

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



[PHP] PHP pop-up windows

2009-02-04 Thread Clancy

I'm working on a website editor, primarily for my own use. Normally it will be 
used on my
own computer, and much of what I wish to achieve could arguably be better done 
in either C
or JavaScript, but both of these have a similar programming syntax to PHP, but 
with subtle
differences, and I don't think my brain could cope with trying to work in two 
similar but
different languages simultaneously.

 An example of what I would like to achieve is:

The primary instance of the program opens a text input window for the user to 
enter, say,
one or more addresses from the contact list. It then pops up a second window, 
which could
be another instance of the same program. In this window the user can search the 
contacts
for the names he wants, and highlight them. When he is satisfied he clicks the 
submit
button on the second window.

When he does this the second window closes, and the primary window detects the 
response,
processes it, and inserts it into the entry area.

I gather that it would be possible for the first program to spawn a child 
process when the
user clicks the button, and this could then open the second window. I think 
that the child
can share session variables with the parent, so the parent could redraw its 
window, then
wait for some flag to be set in the session window, indicating the second 
window was
closing. The parent would then redraw its page incorporating the new 
information.

Is this a feasible mode of operation, and if so would anyone like to suggest 
ways to
implement it, and/or traps to be avoided?



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



[PHP] Re: PHP pop-up windows

2009-02-06 Thread Clancy
On Thu, 05 Feb 2009 01:47:28 +, nrix...@gmail.com (Nathan Rixham) wrote:

>Clancy wrote:
>> I'm working on a website editor, primarily for my own use. Normally it will 
>> be used on my
>> own computer, and much of what I wish to achieve could arguably be better 
>> done in either C
>> or JavaScript, but both of these have a similar programming syntax to PHP, 
>> but with subtle
>> differences, and I don't think my brain could cope with trying to work in 
>> two similar but
>> different languages simultaneously.
...

>> Is this a feasible mode of operation, and if so would anyone like to suggest 
>> ways to
>> implement it, and/or traps to be avoided?
>
>if ever somebody needed flex, it's you

Thanks. But what is flex?

1. Flex electrical cable: I've got plenty of that out in the shed, but it 
doesn't seem to
be relevant here (unless I decide that it is all too much, and decide to hang 
myself with
it!)

2. Single tasking operating system for the Motorola 6800: I once programmed in 
6800
assembler, but I rather doubt if you can buy it, or them, these days.

3. Bodybuilding magazine: too late for that!

4. Adobe application builder - widely criticised for being inflexible: not what 
I'm
looking for.

Perhaps I ought to just give up, and get somebody else to do the job for me, 
but then I
would get the solution to somebody else's problem.  

Also, although my mental agility is less than it used to be, so that I can't 
really handle
working in multiple environments, I still enjoy programming, and it does keep 
my brain
from going rusty!

I have had what seems to me to be a bright idea, and I wondered if anybody had 
tried
anything similar, and could cast any light either on how to go about it, or on 
problems
that I might encounter. 

Just telling me to use something else, without explaining what it is or why it 
is better,
is not really being helpful.

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



[PHP] How can an elephant count for nothing?

2009-02-12 Thread Clancy
While PHP has a lot of nice features, it also has some traps which I am forever 
falling
into. One which I find particularly hard to understand is how mixed mode 
comparisons work.
For instance 

$string =  'elephant';
If($string == 0) returns true;
If($string != 0) returns false;
If($string === 0) returns false; 

I know that in this case I should use 'If($string == '')', but I still manage 
to forget.
Can anyone explain clearly why comparing a string with zero gives this 
apparently
anomalous result?

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



Re: [PHP] How can an elephant count for nothing?

2009-02-12 Thread Clancy
On Thu, 12 Feb 2009 23:47:31 +0800, huixinc...@baidu.com (???) wrote:

>Jochem Maas wrote:
>> Clancy schreef:
>>   
>>> While PHP has a lot of nice features, it also has some traps which I am 
>>> forever falling
>>> into. One which I find particularly hard to understand is how mixed mode 
>>> comparisons work.
.
>> you can avoid auto-casting if needed, in a variety of ways:
>>
>> php -r '
>> $foo = "elephant";
>> if (!empty($foo))
>>  echo "$foo found!\n";
>> if (strlen($foo))
>>  echo "$foo found!\n";
>> if (is_string($foo) && strlen($foo))
>>  echo "$foo found!\n";
>> if ($foo !== "")
>>  echo "$foo found!\n";
>> if ($foo === "elephant")
>>  echo "$foo found!\n";
>> '
>>
>> those last 2 show how to use 'type-checked' equality
>> testing.

>>   
>because  intval("elephant") == 0;
>intval will convert the string into integer , Strings will most likely 
>return 0 although this depends on the leftmost characters of the string.

This seems to be the nearest to the correct answer. In fact it appears that if 
you compare
a string with an integer the effective value of the string is the value of the 
first
character(s), if it/they  are integers, or zero.

elephant == 0; true
an elephant == 0; true
1 elephant == 0; false
0 elephants == 0; true
a herd of elephants == 0; true
7 elephants == 7; true
 elephants == ; true

The next question is ' how is the order of conversion determined?' I thought it 
might have
converted the second element to the same type as the first element, so I 
reversed the
comparison, but I got exactly the same results, so perhaps it converts from the 
more
complex type to the simpler type.

Clearly the lesson is to be learnt is not to compare disparate types, unless 
you really
have to.

One situation where this is unavoidable is if you are searching an arbitrary 
set of
strings for a given word.  In this case it is essential to do the exact 
comparison, or you
will get erroneous results.

Thank you all for your suggestions.

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



[PHP] Re: list all constitute group of array ?

2009-02-14 Thread Clancy
On Sat, 14 Feb 2009 07:41:28 +0800, a...@pc86.com ("LKSunny") wrote:

>$a = array("a", "b", "c", "d");
>
>/*
>how to list:
>abcd
>abc
>ab
>ac
>ad
>bcd
>bc
>bd
>cd
>a
>b
>c
>d
>
>who have idea ? thank you very much !!
>*/
>?>
>

If you are talking about arrays of strings,use my function larec (list array 
recursively).
This has proved to be one of the most useful things I have ever written.  The 
first
parameter is the name of the array (or subsection of an array) you wish to 
list, and the
second parameter is the arbitrary name used for the array in the listing.  (it 
would be
quite easy to modify the procedure to use the actual name of the array, but I 
wrote it
this way, and it is quite handy to be able to use different names if you are 
listing
different sections of the same array. It will work with an array of almost any 
complexity.
I have seen it choof out (almost instantly!) several thousand lines.
'.$line.' = '.$array.'';
}
}
?>
This is a sample of part of a listing. The call for this would have been 'larec
($wkg_data[$entry], 'Entry');

Entry['phone']['ph_o'] = 9978 4749
Entry['phone']['ph_h'] = 
Entry['phone']['ph_m'] = 
Entry['phone']['ph_f'] = 9978 4516
Entry['phone']['ph_a'] = 02
Entry['phone']['ph_e'] = 
Entry['phone']['ph_w'] = 
Entry['phone']['ph_b'] = 

Entry['bursary']['CY']['b_name'] = Cybec Scholarship
Entry['bursary']['CY']['b_status'] = 
Entry['bursary']['EB']['b_name'] = Evan Burge Scholarship
Entry['bursary']['EB']['b_status'] = 
Entry['bursary']['MAP']['b_name'] = Cybec MAP Scholarship
Entry['bursary']['MAP']['b_status'] = 


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



[PHP] PHP strategy -- pass complex parameters by value or by reference?

2009-02-17 Thread Clancy
I have a function to process a data file.  This process opens the file, and 
then calls
another function to process each entry.  This function in turn calls another 
function to
process each line of the entry.  A set of fairly complex arrays specifies how 
all the
possible types of entries and lines should be processed, and each function 
passes sections
of these arrays to the next function.

Is it better to pass the parameters by value, in which case they have to be 
copied into
yet more memory when the function is called, or to pass by reference, which I 
suspect may
involve additional overhead every time they are accessed?

And is it better to combine several specifications arrays into one more complex 
array, and
pass a single parameter, or to pass them individually as half a dozen different
parameters?

I suspect that I am probably asking a "how long is a piece of string?" type of 
question,
but are there any general rules which are applicable to this type of situation?

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



[PHP] Unexpected results using ksort on arrays in which the keys are mixed alphanumeric strings.

2009-02-23 Thread Clancy
I have been experimenting using four character alphanumeric keys on an array, 
and when I
generated a random set of keys, and then used ksort to sort the array, I was 
very
surprised to find that if the key contained any non-numeric character, or if it 
started
with zero, the key was sorted as a base 36 number (0- 9, A-Z, as I expected. 
However if
the key only contained numbers, and did not start with zero, it was sorted to 
the end of
the list.

Thus:

0009
000A

0999
09A0
ASDF


1000


I presume this is related to last weeks discussions about casting variables, 
but I cannot
understand why 0999 should go to the start of the list, while 1000 goes to the 
end. Can
anyone explain this logically?

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



[PHP] Fwrite() vs file_put_contents()

2009-02-24 Thread Clancy
I have been pondering whether it would be feasible to work with a 100,000 entry 
index
file, and had put yesterday aside to do some timing tests. I first generated 
some sample
index files of various lengths. Each entry consisted of a single line with the 
form

ASDF;rhubarb, rhubarb, 

where the ASDF is a randomly generated four character index, and the rest of 
the line is
filling, which varies slightly in length and contents from line to line, just 
in case
something tried to get smart and cache the line.  The average lenth of the line 
is about
80 bytes.

Then I wrote another program which read the file into an array, using the four 
character
index as the key, and the filling as the contents, sorted the array, and then 
rewrote it
to another file, reporting the elapsed time after each step.

My first version used fgets() to read the source file a line at a time, and 
fwrite() to
write the new file. This version performed quite consistently, and took 
approximately 1.3
seconds to read in a 100,000 entry 7.86Mb file, and another 5 seconds to write 
it out
again.

I then read the discussion following fschnittke's post "File write operation 
slows to a
crawl ... " and wondered if the suggestions made there would help.

First I used file() to read the entire file into memory, then processed each 
line into the
form required to set up my matrix. This gave a useful improvement for small 
files, halving
the time required to read and process a 10,000 entry 815 kB file, but for a 
30,000 entry
file it had dropped to about 15%, and it made little difference for a 300,000 
entry file.

Then I tried writing my whole array into a single horrendous string, and using
file_put_contents() to write out the whole string in one bang. I started 
testing on a
short file, and thought I was onto a good thing, as it halved the time to write 
out a
10,000 entry 800 K file. But as I increased the file size it began to fail 
dismally. With
a 30,000 entry file it was 20% slower, and at 100,000 entries it was three 
times slower.

On Shawn McKenzie's suggestion, I also tried replacing fgets() with 
stream_get_line(). As
I had anticipated any difference was well within below the timing noise level.

In conclusion, for short (1MB!) files, using file() to read the whole file into 
memory is
substantially better than using fgets() to read the file a line at a time, but 
the
advantage rapidly diminishes for longer files. Similarly  using 
file_put_contents() in
place of fwrite() to write it out again is better for short files (up to 
perhaps 1 MB) but
the performance deteriorates rapidly above this.


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



Re: [PHP] Unexpected results using ksort on arrays in which the keys are mixed alphanumeric strings.

2009-02-24 Thread Clancy
On Tue, 24 Feb 2009 10:25:25 +0100, joc...@iamjochem.com (Jochem Maas) wrote:

>Clancy schreef:
>> I have been experimenting using four character alphanumeric keys on an 
>> array, and when I
>> generated a random set of keys, and then used ksort to sort the array, I was 
>> very
>> surprised to find that if the key contained any non-numeric character, or if 
>> it started
>> with zero, the key was sorted as a base 36 number (0- 9, A-Z, as I expected. 
>> However if
>> the key only contained numbers, and did not start with zero, it was sorted 
>> to the end of
>> the list.
>
>did your experiment include reading the manual? or did you expect ksort() to 
>known what
>kind of sort you wanted? ... try specifying a sort flag:
>
I have to plead guilty to your first question, but what I really wanted to know 
was how
the sort procedure could decide to treat any key starting with zero as a 
string, but then
decide that any wholly numeric key, not starting with zero, was greater than 
.

But your second question served a useful purpose. I had been thinking that I 
ought to sort
the keys of my index array to speed up the process of fetching a specific entry.
Presumably PHP has to do some form of sort to find the key you have specified, 
but if you
don't know (and can't specify) how it orders the keys there is no point to 
trying to sort
them for it. Then I realised that PHP must have its own highly sophisticated 
indexing
system, and it probably wouldn't make the slightest difference whether or not 
the keys
were sorted.

So I made several different dummy index files with random keys, some sorted and 
some
unsorted, and timed how long it took to see if every key on one file was set in 
one of the
other files. This showed first that it didn't matter whether or not the keys in 
the second
file were sorted, and, more importantly, that the 'if(isset())' process is so 
fast that in
any situation I can think of you can completely ignore it. Testing all the keys 
of one
100,000 entry array against another 100,000 entry array took only 300 
milliseconds, or
about 3 µs per test.


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



Re: [PHP] whoami explanation

2009-03-03 Thread Clancy
On Tue, 3 Mar 2009 11:09:48 -0500, danbr...@php.net (Daniel Brown) wrote:

>On Tue, Mar 3, 2009 at 11:03, PJ  wrote:
>>>
>> ok, ok, I found it but you guys are assuming that this is something
>> everybody should know... hell, I've been tinkering with programming and
>> unix etc. for many, many years and this is the first time I ran into
>> back quotes.
>> SORRY!
>
>You're assuming that we're assuming something (though I don't even
>know to whom that's supposed to be directed).
>
>Backtick operators have been around since the inception of UNIX
>itself.  I don't mean this offensively by any means whatsoever, but if
>you haven't run into them before, you haven't been tinkering very
>much.

In my 40 plus years of programming I don't think I have ever deliberately typed 
a back
tick, and had forgotten that it was on the keyboard. And I have tinkered with 
all sorts of
strange systems, but I have had very little to do with UNIX.

This discussion reminds me of the "Any" key as in: 

Support person "now press any key". User "but there isn't an "Any" key on my 
keyboard!

Clancy

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



[PHP] Re: if elseif elseif elseif....

2009-03-05 Thread Clancy
On Wed, 04 Mar 2009 17:51:11 -0500, af.gour...@videotron.ca (PJ) wrote:

>This is probably a mysql question, but their list is rather dull - I
>think they don't appreciate my humor. Beside this list is fun ... and
>informative.
>Anyway, I can't figure this out. I am trying to verify inputs on a form
>and even if I have all the required fields right, I still get the error
>that there are empty obligatory fields.
>This is what I am using... but I'm open to anything that works or is
>more efficient:
>   
>if (strlen($_POST["titleIN"]) == 0 ) {
>$obligatoryFieldNotPresent = 1;
>}
>elseif (strlen($_POST["first_nameIN"]) == 0 ) {
>$obligatoryFieldNotPresent = 1;
>}
>elseif (strlen($_POST["publisherIN"]) == 0 ) {
>$obligatoryFieldNotPresent = 1;

Rather than encoding all the variable names into one long unwieldy set of 
statements, I
would put them all into an array, and then use a loop to process the array. 
This way all
the variable names are together, and the next time you want to enter another 
set of
variables you can use the same code, but read from a different array. 

For example:

   $oblig_fields = array('TitleN', 'first_nameN', '');
   $ok = true; 
   $i = 0; while ($i < count($oblig_fields && $ok))
{
if (!isset($_POST[$oblig_fields[$i]]) || ($_POST[$oblig_fields[$i]] == 
''))
{
$ok = false;
}
else
{
$results[$oblig_fields[$i]] = $_POST[$oblig_fields[$i]];
}
++$i;
}
   if (!$ok) { echo 'Scream!!!'; }

once you have the basic code working, you can easily add extra frills. For 
example if only
some of the fields were compulsory, you could have one array $all_fields, and 
another
$oblig_fields. Then, as you processed each entry using $all_fields, you would 
only break
one missing data if that key was set in $oblig_fields.

I am sure you could use a "break" statement in place of the "$ok = false;" 
above, but I
have never trusted the break statement. To my mind it is like a GOTO without a 
target. As
I used to tell my students "When I say break, the only thing I can be certain 
of is that
the lecture theatre will be empty in 30 seconds. I have no idea where most of 
you go, and
I don't know if I will ever see some of you again."

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



Re: [PHP] Re: if elseif elseif elseif....

2009-03-05 Thread Clancy
On Fri, 06 Mar 2009 10:16:47 +1100, dmag...@gmail.com (Chris) wrote:

>
>> Rather than encoding all the variable names into one long unwieldy set of 
>> statements, I
>> would put them all into an array, and then use a loop to process the array. 
>> This way all
>> the variable names are together, and the next time you want to enter another 
>> set of
>> variables you can use the same code, but read from a different array. 
>> 
>> For example:
>> 
>>$oblig_fields = array('TitleN', 'first_nameN', '');
>>$ok = true; 
>>$i = 0; while ($i < count($oblig_fields && $ok))
>>  {
>>  if (!isset($_POST[$oblig_fields[$i]]) || ($_POST[$oblig_fields[$i]] == 
>> ''))
>>  {
>>  $ok = false;
>>  }
>>  else
>>  {
>>  $results[$oblig_fields[$i]] = $_POST[$oblig_fields[$i]];
>>  }
>>  ++$i;
>>  }
>>if (!$ok) { echo 'Scream!!!'; }
>
>The problem with that is if I miss 5 fields, I have 5 page refreshes to 
>get to the end & actually successfully submit the form. If you keep an 
>array of broken entries (per my previous suggestion) you get all the 
>form fields missed in one go.

Easily fixed. Just put: 

$missing = false; 

at the start of the loop, and then:

$missing[$oblig_fields[$i]] = true; 

each time you find a missing field. Then the array keys for $missing will tell 
you which
fields you have to fetch again.

>I'd just do a foreach instead of a while, count, and counter.
>
>foreach ($oblig_fields as $field_name) {
>   if (!isset($_POST[$field_name]) || empty($_POST[$field_name])) {
> 
>   }
>}
>
>> I am sure you could use a "break" statement in place of the "$ok = false;" 
>> above, but I
>> have never trusted the break statement. To my mind it is like a GOTO without 
>> a target.
>
>Must've been a bad experience ;) Always works for me.

Don't take me too seriously on this. But it riles me that the same peoplewho 
threw out the
GOTO as being too dangerous could then introduce the break statement which, as 
I said,
it's like a GOTO without a target. As a long-time assembly programmer, I found 
the
judicious use of GOTO's made for far clearer code than the mess of nested 
braces I am
forced to use in PHP.


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



[PHP] Website on a USB key?

2009-03-05 Thread Clancy
I bought some appliance recently, and found that they had thrown in a 2G USB 
key for good
luck.  I guess I ought to be able to put a PHP server plus a copy of my website 
on it for
demonstration purposes, but has anyone actually tried it, and if so are there 
any traps to
avoid?

Thanks,

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



Re: [PHP] Re: if elseif elseif elseif....

2009-03-06 Thread Clancy
On Fri, 6 Mar 2009 08:53:44 -0500, danbr...@php.net (Daniel Brown) wrote:

>On Fri, Mar 6, 2009 at 00:12, Clancy  wrote:
>>
>> Don't take me too seriously on this. But it riles me that the same peoplewho 
>> threw out the
>> GOTO as being too dangerous could then introduce the break statement which, 
>> as I said,
>> it's like a GOTO without a target. As a long-time assembly programmer, I 
>> found the
>> judicious use of GOTO's made for far clearer code than the mess of nested 
>> braces I am
>> forced to use in PHP.
>
>Then you'll be happy with the advent of PHP6:
>
>http://php.net/goto

Great news! .. Now ALL I have to do is to persuade my host to update from 
4.3.9. (or
maybe switch!)


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



Re: [PHP] Website on a USB key?

2009-03-06 Thread Clancy
On Fri, 6 Mar 2009 05:51:36 -0800 (PST), seanodot...@yahoo.com (Sean O) wrote:

>
>Another good website-on-a-stick software is... well, WOS (now called MoWeS --
>Modular Webserver System).
>http://www.chsoftware.net/en/useware/mowes/mowes.htm
>
>The nice thing about this software is the ability to download "packages" of
>just about any major server-based software -- Drupal, Mambo, Joomla, Moodle,
>SugarCRM, WordPress, etc.
>http://www.chsoftware.net/en/useware/mowesmixer/mowesmixer.htm?step=2
>
>And, of course, run it all from your USB Drive.
>
Thanks,

That sounds like what i was thinking of.  The only reason for doing such a 
thing is so you
can poke the key into someone elses PC & run a demo without changing anything 
on their
machine.

Not a high priority though; I already have my websites on my laptop.


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



Re: [PHP] Re: if elseif elseif elseif....

2009-03-06 Thread Clancy
On Fri, 6 Mar 2009 08:58:17 -0600, halip...@gmail.com (haliphax) wrote:

>>> >> >    I wholeheartedly concur.  The first programming language I taught
>>> >> > myself was BASIC about 23 years ago.  We may never see the inclusion
>>> >> > of GOSUB in PHP, but GOTO is certainly worthwhile.
>>> >> >
>>> >> >
>>> >> >    Side note: I wrote a BASIC interpreter in PHP about two weeks ago.
>>> >> >  Talk about fond memories.
>>> >>
>>> >> QuickBasic (actually QBasic, and then later QuickBasic when my mom
>>> >> shelled out the money for me to buy it) was my first language. I
>>> >> remember being completely flabbergasted when I found out they packaged
>>> >> an interpreter with DOS, and it had been under my nose the whole time.
>>> >> I think my first "finished" program was a D&D character generator.
>>> >> Basically, just colored and formatted text with the output of 6 or so
>>> >> random number generations.
>>> >>
>>> >> Meemorees... :D
>>> >
>>> > I did Basic on the TRS-80 and saved my programs to a big clunky audio
>>> > tape drive... 1... 2... 3... queue Tedd with rocks :)
>>>
>>> Oh, I'm not even trying to pretend like I'm half as old as some on
>>> this list. I still chew my own food, thank you very much. ;)
>>>
>>> (All in jest, of course... But some of you are pretty old. Ha!)
>>
>> I just turned 35... today... that's young by the standards of a 70 year
>> old >:)
>
>Well, I may not be decrepit just yet, but I am by no means a
>whippersnapper anymore. Looking at turning 27 this April. I'm sure
>some of the more geriatric people in the world still consider me a
>kid, but I can look at teenagers now and think, "What the hell are
>they doing that for?"

Yes, when I went to university the students were young adults. Now they are 
just kids!

When I started programming (in about 1967) I worked for the Commonwealth 
Scientific and
Industrial Research Organisation (CSIRO) in Australia. They had a little 
computer (a CDC
3200, costing $500,000 and with 32K of 24 bit words of core memory) in each 
capital city,
and a big computer (a CDC 3600, costing $2,000,000 and with 64K of 48 bit words 
of memory)
in Canberra. The little computers filled a large room, and had about 20 people 
operating
them. The big one filled a whole floor, and had about 50 people operating it.

I had to enter my programs on punch cards, and a courier would collect them 
twice a day
and take them to Clayton (another site about 10 miles away). Then he would 
bring back the
listings from the previous trip. After the morning run we had about 20 minutes 
to fix
obvious bugs before he collected the next batch, and we had overnight to fix 
the afternoon
run. When I got more ambitious, and started using the big computer, the cards 
were taken
to Clayton where they were transferred to mag tape, which was couriered to the 
airport and
flown to Canberra. The tapes were run overnight, and the listings written back 
to tapes,
which were flown back to Melbourne next morning, taken to Clayton, transferred 
to paper,
and brought back to our site. There was often fog in Canberra, which would 
close the
airport, so if we were lucky we would get three runs in a week. Any trivial 
change would
take a week to debug.

We were programming in Fortran, and the I/O support was extremely primitive. 
You had to
specify the format for every value you wished to read - eg F10.3 for a 10 digit 
floating
point number, with three digits after the decimal point, and you had to place 
the decimal
point in a specific column on the card. Despite all this I wrote a complex 
program for
analysing linear electronic circuits. It was effectively an interpreter for my 
own
high-level language.

I never understood how subroutines worked, as the concept of stacks had not been
developed, and you could jump into or out of loops and even subroutines with 
impunity. It
also had an 'assigned goto' instruction, which was perfect for writing 'write 
only'
software. My program was very simple. It consisted of a loop:

Assign initial pointers to switches 1 to 3;
Start: read a character;
if it's a number { GOTO switch_1; }
if it's a punctuation mark { GOTO switch_2; }
if it's anything else { GOTO switch_3; }
GOTO Start;

Initial_switch_1 procedure:
.
GOTO start;

Each time I found something interesting I would assign a new pointer to the 
appropriate
switch. This gave extremely compact code, enabling me to get my complicated 
program into
the ridiculously small memory, but I soon found that it was virtually 
impossible to debug,
as the settings of the switches at any moment depended on the whole previous 
history.

Presumably others made the same discovery, as the assigned goto never appeared 
on any
subsequent computer.

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



Re: [PHP] Re: if elseif elseif elseif....

2009-03-07 Thread Clancy
On Sun, 8 Mar 2009 01:54:22 +0600, le...@phpxperts.net (9el) wrote:

>>
>>
>> They probably thought you couldn't handle the responsibility... and if
>> you can't think for yourself then they may be right ;)
>>
>> > Once we have goto, it's a short slide down a slippery slope to setjmp
>> > and longjmp. And thence, the apocalypse. ;-}
>>
>> Or maybe nirvana is just over the horizon! You can't know until you go
>> there.
>>
>>
>> As goto is unconditional it can make endless loop... but I think its been
>overcome'd already

And YOU can't make an endless lop with braces???  I manage to do it about once 
a week!


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



[PHP] Opendir on site root directory?

2009-03-07 Thread Clancy
I want to index the files on a website recursively. The program will run in the 
site root
directory, which GETCWD reports as D:/Websites/Website_1.  I can open any file 
in the root
directory simply using its file name; Joe.dat, for example, and I can opendir 
for any
subdirectory; eg 

opendir(Subdirectory_1); 

but opendir () does not seem to work, and the only way I can find to open the 
root
directory is to give its full path; eg 

opendir (D:/Websites/Website_1);

I have got the program working by using the full path to open the root 
directory, and then
using relative paths to open the subdirectories and individual files, but this 
seems
rather a kludge, and I am wondering if there is a way to open the root 
directory without
specifying an absolute path?

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



Re: [PHP] Opendir on site root directory?

2009-03-08 Thread Clancy
On Sun, 8 Mar 2009 09:01:18 +, stut...@gmail.com (Stuart) wrote:

>2009/3/8 Clancy 
>
>> I want to index the files on a website recursively. The program will run in
>> the site root
>> directory, which GETCWD reports as D:/Websites/Website_1.  I can open any
>> file in the root
>> directory simply using its file name; Joe.dat, for example, and I can
>> opendir for any
>> subdirectory; eg
>>
>>opendir(Subdirectory_1);
>>
>> but opendir () does not seem to work, and the only way I can find to open
>> the root
>> directory is to give its full path; eg
>>
>>opendir (D:/Websites/Website_1);
>>
>> I have got the program working by using the full path to open the root
>> directory, and then
>> using relative paths to open the subdirectories and individual files, but
>> this seems
>> rather a kludge, and I am wondering if there is a way to open the root
>> directory without
>> specifying an absolute path?
>
>
>The current working directory cannot be trusted to be "right". The best
>option is to use dirname(__FILE__) and add '/..' as many times as needed to
>get from the current file to the document root you're after.

It has always worked for me.  But then I never change directory. But both give 
a hardware
dependent answer; 

echo 'Current directory is '.__FILE__.', CWD is '.getcwd().''; gives

Current directory is D:\Websites\Corybas\Cydaldev\Dev\Testbed_2.php, CWD is
D:\Websites\Corybas.

Opendir (Dev); works, opendir (); ought logically to work, but doesn't. (It 
complains it
needs at least one parameter.)

Eventually I found that 

opendir('../Cydaldev'); does not work
chdir(Cydaldev); opendir ('..'); does work, but I can't say I like this.

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



Re: [PHP] Opendir on site root directory?

2009-03-08 Thread Clancy
On Sun, 8 Mar 2009 12:33:15 +, stut...@gmail.com (Stuart) wrote:

>2009/3/8 Clancy 
>
>> On Sun, 8 Mar 2009 09:01:18 +, stut...@gmail.com (Stuart) wrote:
>>
>> >2009/3/8 Clancy 
>> >
>> >> I want to index the files on a website recursively. The program will run
>> in
>> >> the site root
>> >> directory, which GETCWD reports as D:/Websites/Website_1.  I can open
>> any
>> >> file in the root
>> >> directory simply using its file name; Joe.dat, for example, and I can
>> >> opendir for any
>> >> subdirectory; eg
>> >>
>> >>opendir(Subdirectory_1);
>> >>
>> >> but opendir () does not seem to work, and the only way I can find to
>> open
>> >> the root
>> >> directory is to give its full path; eg
>> >>
>> >>opendir (D:/Websites/Website_1);
>> >>
>> >> I have got the program working by using the full path to open the root
>> >> directory, and then
>> >> using relative paths to open the subdirectories and individual files,
>> but
>> >> this seems
>> >> rather a kludge, and I am wondering if there is a way to open the root
>> >> directory without
>> >> specifying an absolute path?
>> >
>> >
>> >The current working directory cannot be trusted to be "right". The best
>> >option is to use dirname(__FILE__) and add '/..' as many times as needed
>> to
>> >get from the current file to the document root you're after.
>>
>> It has always worked for me.  But then I never change directory. But both
>> give a hardware
>> dependent answer;
>>
>> echo 'Current directory is '.__FILE__.', CWD is '.getcwd().''; gives
>>
>> Current directory is D:\Websites\Corybas\Cydaldev\Dev\Testbed_2.php, CWD is
>> D:\Websites\Corybas.
>
>
>Not sure what you mean by a hardware-dependent answer. The current working
>directory for any given script is determined by the web server and so it
>cannot be assumed to be the location of the current script.
>dirname(__FILE__) will give you the directory the current script is in.

I agree that 'hardware dependent' was not the right word, but what I meant was 
that if I
am running the local version of my program getcwd() will return 
'D:\Websites\Corybas',
where as if I am running the remote version it will return 
'home/Corybasftp/www'.

My webpage is always launched by loading index.php from the root directory, and 
I don't
think I ever change the working directory, so although the code actually being 
executed at
any given time is usually in a subdirectory, getcwd() will reliably return the 
(system
dependent) long definition of the root directory.
>

>Based on that the following should work in your particular situation, but
>rather than just using this I encourage you to understand why it works...
>opendir(dirname(__FILE__).'/../Cydaldev');

Looking into this I did find that 'opendir('Albums/../');', where 'Albums' can 
be any
subdirectory I know to be present, will reliably open the root directory.

Initially I built my index starting from the path returned by getcwd(), but 
when I got it
working I realised that, as it contained the system dependent information, it 
would be
useless on the remote server.

As a result of what seems to me to be an oversight in the design of opendir(), 
in that
opendir(Fred) and opendir(Fred/Nurg) will open the appropriate sub directories 
but
opendir() will not open the root directory, I can readily index all the 
subdirectories by
giving their relative paths, but I have to resort to a kludge to index the root 
directory,
and another kludge to eliminate this kludge from the index. 

If, as it seems, I have to accept this it is fairly immaterial which kludge I 
actually
use.


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



Re: [PHP] Opendir on site root directory?

2009-03-09 Thread Clancy
On Mon, 9 Mar 2009 10:07:33 +, stut...@gmail.com (Stuart) wrote:

...
>As in the example script I've posted above you can refer to the current
>working directory with a single period (.), but this is still relying on the
>current working directory being what you expect it to be.

Thank you! This is what I had been looking for all along. I dimly remembered 
some such
trick, but it had become lost in the detritus at the back of my mind.

But why the obsession with avoiding getcwd()? When my site is loaded the 
current directory
is always the root directory of the page, and as I never change directory I can 
rely on it
staying there. (And, incidentally, since getcwd(), dirname(__FILE__), etc, all 
return the
complete path including system dependent information, if I really didn't know 
the current
directory it would not be a trivial task to determine what was the local root.)

For a couple of years I have been using getcwd() to determine whether or not I 
am running
on my local PC (if I am the path will start with 'D:'). If I am running on the 
local PC I
load various editing and other private facilities, otherwise I omit them. This 
is done in
such a way that there is nothing to indicate that anything is either missing or 
has been
omitted.

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



[PHP] Re: More PHP Includes

2009-03-10 Thread Clancy
On Tue, 10 Mar 2009 09:59:53 -0400, gwp...@ptd.net ("Gary") wrote:

>Thanks again for all the help.
>
>I created a simple page of all includes (header, menu, 3 columns).  I mixed 
>the file types up. The menu (projectseven PMM) I saved as a library item, 
>works fine.  Had an HTML file in there, but I am guessing that having 2 page 
>declarations along with an extra set of  and  tags was playing 
>havoc with the code, so I removed them. Same thing when I created a php page 
>and saved it as filename.inc.php, so I removed all the declarations and 
>tags, again seems to work fine. Also included a simple .txt file.
>
>I did get some strange results in that all of the  were highlighted 
>after the menu, and I had to remove and insert again to correct.
>
>So is this the best way, to create a php page, remove all of the html tags 
>and page declarations and name it filename.inc.php? (I'm using DW CS3)

The main file should set up the page (, , etc).  The include file 
can have any
mixture of HTML and PHP, including defining tables, etc. If it contains any PHP 
it should
be named as x.php. It is also good practice to put  at the
end, though it doesn't appear to make any difference.

>Also, something I do not understand, I included a small txt file in a page 
>of a customer and it shows fine, however this file is not on the server...is 
>this normal? 

Sorry; I don't understand this.


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



[PHP] Working directory of PHP pages?

2009-03-10 Thread Clancy
It is my understanding that when you open a page the PHP server looks for 
index.php in the
site root directory, and loads it. As a result the working directory of the 
page will be
the root directory of the site.  I have always worked on this assumption, and 
it has
always been correct.  On the other hand Stewart thinks that I cannot rely this, 
and am
likely to get into trouble as a result.

Are there any systems in which my assumption will not be correct?


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



Re: [PHP] Opendir on site root directory?

2009-03-10 Thread Clancy
On Tue, 10 Mar 2009 15:12:57 +, stut...@gmail.com (Stuart) wrote:

>Please keep the discussion on-list.
>
>2009/3/10 Clancy 
>
>> Hi,
>>
>> After I posted my message to the group today I realised that my program
>> achieves its
>> almost infinite flexibility by loading different include files in different
>> circumstances,
>> and from many different parts of the program.  The program always specifies
>> the location
>> of the include file by the relative path from the root directory.   If the
>> uncertainty
>> about the current working directory you worry about were really a problem
>> this would never
>> work, but I have been doing this for well over a year, and had never had
>> any problems.
>>
>
>Just because you haven't experienced a problem with the way you do things
>yet it certainly doesn't mean the problem isn't there. You're not specifying
>the location of an include file relative to the home directory, it's
>relative to the current working directory which is not necessarily the
>directory you expect it to be.

The only circumstances in which my assumption could fail would be if I changed 
to a new
provider with a different operating system. In the unlikely event of this 
happening all I
would need to do would be to determine the actual directory, and chdir to the 
desired one.
This would require at most half a dozen lines of code at the start of the 
program, so it
would not be a significant hassle.


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



Re: [PHP] Re: Working directory of PHP pages?

2009-03-11 Thread Clancy
On Wed, 11 Mar 2009 13:03:19 -0500, halip...@gmail.com (haliphax) wrote:

>On Wed, Mar 11, 2009 at 12:44 PM, Shawn McKenzie  wrote:
>> Clancy wrote:
>>> It is my understanding that when you open a page the PHP server looks for 
>>> index.php in the
>>> site root directory, and loads it. As a result the working directory of the 
>>> page will be
>>> the root directory of the site.  I have always worked on this assumption, 
>>> and it has
>>> always been correct.  On the other hand Stewart thinks that I cannot rely 
>>> this, and am
>>> likely to get into trouble as a result.
>>>
>>> Are there any systems in which my assumption will not be correct?
>>>
>>
>> In many frameworks this assumption is not correct.  I am using the
>> default CakePHP layout as an example.
>>
>> Depending on your terminology, your DocumentRoot is /var/www/ and in
>> this case is also the filesystem path of your site's root dir, however
>> the sites root dir in a URL is /.
>>
>> Consider the CakePHP structure:
>>
>> /var/www/
>>  .htaccess
>>  index.php
>> /var/www/webroot
>>  index.php
>>
>> If you browse to http://example.com/ (in most cases), one of 2 things
>> happens:
>>
>> 1. The webserver opens the /var/www/.htaccess and according to the
>> rewrite rules there it rewrites to /var/www/webroot/.  So any getcwd()
>> would be /var/www/webroot/
>>
>> 2. If not using modrewrite, the web server looks for index.html and then
>> index.php in /var/www/ which has a require for webroot/index.php.  So
>> any getcwd() would be /var/www/.
>>
>> Consequently, CakePHP and the other frameworks that I've seen use
>> basename() and dirname() in conjunction with __FILE__ to define the
>> paths/relative dirs within the app.
>
>Come to think of it, this may very well be true for all MVC frameworks
>(unless the models, views, and controllers are all in the same
>directory as the launch script). I can at least vouch for the fact
>that CodeIgniter, like CakePHP, will fudge your directory estimation
>if you're expecting getcwd() to be right.

Something Stewart said the other day made me realise that there was a 
fundamental error in
the way I was thinking about this question. I had been thinking that opendir 
(.) opened
the root directory, and that paths such as Joe/Nurg.com were relative to the 
root
directory, but I now realise that they are relative to the current directory, 
whatever
that might be. (Yes; I should have known better, but there is an awful swamp of 
burnt out
brain cells at the bottom of my brain.)

So the question I should have asked was "When a web page is loaded, can I rely 
on the CWD
being the directory containing index.php (or whichever file is actually 
loaded)?"

Thank you all for your assistance.


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



[PHP] Re: strcmp() versus ==

2009-03-17 Thread Clancy
On Mon, 16 Mar 2009 17:06:35 -0500, nos...@mckenzies.net (Shawn McKenzie) wrote:

>Shawn McKenzie wrote:
>> Paul M Foster wrote:
>>> I had never completely read over the rules with regard to comparisons in
>>> PHP, and was recently alarmed to find that $str1 == $str2 might not
>>> compare the way I thought they would. Is it common practice among PHP
>>> coders to use strcmp() instead of == in making string comparisons? Or am
>>> I missing/misreading something?
>>>
>>> Paul
>>>
>> 
>> I would use $str1 === $str2 if you want to make sure they are both
>> strings and both the same value.
>> 
>> Since PHP is loosely typed, "0" == 0 is true however "0" === 0 is false.
>> 
>
>If you want to force a string comparison you can also use:
>
>(string)$str1 == (string)$str2

Recently there was some discussion about inexplicable results from sorting 
alphanumeric
strings.  Inspired by your suggestion I filled in an array with random 4 
character
alphanumeric strings, and then wrote a simple bubblesort.  I made two copies of 
the array,
and sorted one using a simple comparison, and the other using the above 
comparison.  The
initial values of the array were :

$aa = array 
('ASDF','01A3','0A13',1,'00A3','','001A','','7205','00Z0'); 

(There are no letter 'O's in this),

And the results I got were:

Tb2_38: Original   Raw comp   String Comp
ASDF   
01A300A3   001A
0A1301A3   00A3
1   0A13   00Z0
00A3ASDF   01A3
  0A13
001A1 1
001A   7205
720500Z0   ASDF
00Z07205   

Apart from the out of place '1', apparently treated as '1000', which I threw in 
out of
curiosity, the string comparison gave the expected results, but I cannot see 
the logic of
the raw comparison.  Can anybody explain these results?

Clancy

If anyone is suspicious the actual code I used was:


$aa = array 
('ASDF','01A3','0A13',1,'00A3','','001A','','7205','00Z0'); 

$k = count ($aa); $bb = $aa; $cc = $aa;
while ($k > 1)
{
$i = 0; $j = 1; while ($j < $k)
{
if ($cc[$i] > $cc[$j])
{
$t = $cc[$i]; $cc[$i] = $cc[$j]; $cc[$j] = $t;
}
++$i; ++$j;
}
--$k;
}

$k = count ($aa);
while ($k > 1)
{
$i = 0; $j = 1; while ($j < $k)
{
if ((string)$bb[$i] > (string)$bb[$j])
{
$t = $bb[$i]; $bb[$i] = $bb[$j]; $bb[$j] = $t;
}
++$i; ++$j;
}
--$k;
}

echo 'Tb2_38: Original   Raw comp   String 
Comp'; 
$i = 0; $k = count ($aa);
while ($i < $k)
{
echo '    
    '.$aa[$i].
''.$cc[$i].
 
'   '.$bb[$i].'';
++$i;
}

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



Re: [PHP] redirect to a page the fist time a site is accessed

2009-04-16 Thread Clancy
On Thu, 16 Apr 2009 09:26:52 -0500, nos...@mckenzies.net (Shawn McKenzie) wrote:

>Stuart wrote:
>> 2009/4/15 Don :
>>> I have some code in my index.php file that check the user agent and
>>> redirects to a warning page if IE 6 or less is encountered.
>>>
>>> 1. I'm using a framework and so calls to all pages go through index.php
>>> 2. The code that checks for IE 6 or less and redirects is in index.php
>>>
>>> I know how to redirect the users but what I want to do is redirect a user
>>> ONLY the first time the web site is accessed regardless of what page they
>>> first access.  I would like to minimize overhead (no database).  Can this be
>>> done?
>> 
>> Why redirect? That sucks as a user experience. Why not simply put an
>> alert somewhere prominent on the page with the message you want to
>> convey? That way you can have it on every page and not interrupt the
>> users use of your site.
>
>I agree, and you can still try the cookie method to not show the
>message, but it's not a big deal if they don't get the cookie/it expires
>etc., because the worst thing that can happen is that they see the message.

Alternatively add a link 'If you are new/Introduction/etc' that the new user 
can click to
get more information if they want it.


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



Re: [PHP] speaking of control structures...

2009-05-05 Thread Clancy
On Tue, 05 May 2009 14:13:23 -0400, rob...@interjinn.com (Robert Cummings) 
wrote:

>On Tue, 2009-05-05 at 13:56 -0400, Tom Worster wrote:
>> there's a control structure i wish php had: a simple block that you can 
>> ...

>But PHP 5.3 introduces goto:
>
>
>header:
>
>if( $something ) ...
>
>goto body;
>
>body:
>
>if( $soemthingElse ) ...
>goto footer;
>
>if( $seomthingerElse ) ...
>
>goto footer;
>
>footer:
>
>// blah blah blah
>goto done;
>
>done;

I heartily agree. In my opinion 'break' is like a 'goto' without a label. As I 
used to
tell my students "if I say 'break' the one thing I can be sure of is that you 
will all
disappear. I had no idea where most of you go, or what you do, and I'm not even 
sure if
I'll ever see some of you again."

'Goto' makes it possible to set up the more complex control sequences you 
sometimes need,
yet have them clearly defined. For example:



I find it very difficult to set up sequences like this using if/else if (or 
switches, but
I don't like them anyway), and have to resort to setting flags and very careful
indentation to make sure that I'm doing what I intended. Unfortunately my 
provider is
still using PHP 4.something, and I have been too busy to switch to someone more
up-to-date.


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



Re: [PHP] speaking of control structures...

2009-05-06 Thread Clancy
On Wed, 06 May 2009 08:54:14 -0400, f...@thefsb.org (Tom Worster) wrote:

...
>clancy, i can't argue with you. my desired usage of break is really just a
>cover-up for a goto. i know.
>
>it makes no logical sense but i think i'd sooner adopt oop than gotos. my
>mom taught me to program back in the late 70s and early 80s. she was an old
>hand. when FORTRAN 4 came out she thought it was the bees knees. when Z80
>micros with MS-BASIC came out, she thought they were cute. when turbo pascal
>came out on CP/M, she was impressed and taught me to quit using gotos.
>
>so while it makes no logical sense, perhaps you can see that it makes
>emotional sense.
>

I can understand your reluctance to disregard your mother's advice, but 
unfortunately she
had been brainwashed to accept the dogma of the day. I could never understand 
the hysteria
relating to GOTO. Certainly it could be abused, as I knew to my cost, but it is 
clear and
explicit, whereas both break and exception are disguised GOTO's with 
ill-defined targets.

I started programming in 1967, in Fortran. There were only the most basic 
computer
manuals, and CSIRO (for whom I worked) had a little computer (a CDC3200, with 
32K of 24
bit words, and costing only $500,000) in each capital city, and a big computer 
(a CDC3600,
with 64K of 48 bit words, and costing $2 million) in Canberra. Our local 
computer was at
Clayton, and I worked at Highett, so a courier collected our punch cards twice 
a day and
took them to the local computer, then brought back the results of the previous 
run, giving
effectively one and a half runs a day.

When I got ambitious, and needed to use the big computer, my cards were put on 
to mag tape
at Clayton, and flown to Canberra, where they were run through the 3600 
overnight, and the
results written back to mag tape. Next morning the tapes were flown back to 
Melbourne,
driven to Clayton, run through the 3200 to produce listings, and these were 
then delivered
back to Highett. The flights were often delayed by fog in Canberra, and on 
average we got
three runs a week.

Programming was in its infancy, and the idea of using a stack to handle 
subroutines had
not been introduced (at least by CDC). The Fortran provided an assigned GOTO, 
which really
was the perfect instruction for writing 'write only' code. It also permitted 
you to jump
indiscriminately into, or out of, loops and subroutines, and it was probably 
abuse of
these options which gave the GOTO its bad name. 

I was developing a program for analysing linear electronic circuits, and 
effectively
developed my own interpreted language. The program was very simple; it 
consisted of a loop
containing three assigned GOTO's:

start:  assign begin to switch_one
assign  

next:   read the next character
if it's a number, GOTO switch_one
if it's a punctuation mark, GOTO switch_two
GOTO switch_three

begin:
.
GOTO next
end:

I left CSIRO in 1973, and did not have access to a big computer until about 
1983. By this
time the assigned GOTO had long since vanished, and I had great difficulty 
understanding
my original logic, until I unrolled the inner loop into a logical progression 
through the
possible inputs.

For the next 20 years most of my programming was in 8x86 MASM. This also had 
the GOTO, and
I was able to write extremely complex programs, despite its inherent verbosity, 
by
developing subroutines to handle all the basic procedures, and using GOTO's to 
define the
control structure.


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



Re: [PHP] speaking of control structures...

2009-05-07 Thread Clancy
On Thu, 07 May 2009 09:33:00 -0400, f...@thefsb.org (Tom Worster) wrote:

>On 5/6/09 9:31 PM, "Clancy"  wrote:
>
>> I can understand your reluctance to disregard your mother's advice, but
>> unfortunately she
>> had been brainwashed to accept the dogma of the day.
>
>actually, i don't believe so. she did numerical work so she continued using
>fortran and therefore gotos for the rest of her life. i think she just
>didn't like goto. moreover, she was never dogmatic on any topic, it wasn't
>in her nature.
>
>anyway, how do you know how she came by her opinions?
>

I did not say your mother was dogmatic; but clearly she had accepted the dogma 
of the day,
as there is no rational reason to avoid the goto. Assuredly the goto can be 
misused, but
this attitude is rather like that of my wife, who is extremely reluctant to use 
my sharp
kitchen knives 'because they are dangerous', and insists on using her own worn 
out
implements that are barely suitable for buttering toast. I know my knives are 
dangerous --
the odd bit of finger occasionally sneaks into the dinner -- but they are 
essential to do
the job properly, and in my opinion the goto comes in the same category.

Another very useful feature of my original program was that it had an error 
handler at the
end, and if I detected an error, anywhere in the program, I simply said 'goto 
error'. This
was an assigned goto, so that I could set up error handlers for particular 
circumstances
if I wished. This was no longer possible in more modern versions of Fortran, 
and I had to
set up, and keep track of, a complicated system of error flags to achieve the 
same result.
Reading this discussion, I was amused to realise that the modern system of 
exceptions, and
exception handlers, was designed to achieve the same end.

The operating system was extremely unfriendly, as if it detected an error it 
simply
terminated the job with an inscrutable message. As I only got three runs a week 
anyway I
went to great lengths to avoid this. I even developed my own plotter driver, as 
the system
one would terminate the plot if any command went outside the specified working 
area. This
was usually the result of a typo, and would come good on the next instruction, 
so when my
driver detected that the pen had reached the edge of the working area, it would 
raise it,
and keep track of the position until the pen came back into the working area, 
whereupon it
would lower it and continue plotting. 

This was relatively simple, as the plotter only had three commands; pen up, pen 
down, and
step one step in any of the eight directions of the compass. On the other hand 
it meant I
had to develop my own font set and electronic symbols.


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



[PHP] Comparing strings (revisited)

2009-05-24 Thread Clancy
For some time I have been working on a text based database, in which each entry 
contains
one or more lines of data, with the various fields delimited by semicolons, e.g.

A;b;20GM;Restaurant;090508
n;;;Arintji;;
a;Federation Square;;;
p;9663 9900;;;9663 9901;;i...@arintji.com.au;

All was going well but recently I decided to allocate every entry a unique 
identifier,
and, in what with hindsight was clearly misguided enthusiasm, decided that each 
identifier
should be a four digit base 36 number (the 20GM in the first line). This did 
not cause any
problems until yesterday, when I tried to load a name beginning with 'R', and 
got the
first name on the list. When I investigated I found that I was searching the 
array
containing the data using:

if ($ident == $data[$i]['group']['ident'])  { ..

I then found that I was searching for 20E2, but was getting a match on 2000. I 
tried 

'if ((string) $ident == (string) $data[$i]['group']['ident'])', 

but this still matched. However 

'if($ident === ' 

worked, as did 

'if (!strcmp($ident, $data[$i])) {...'.

After puzzling about this for a long time, I realised that the comparison 
process must
have been treating the second value as a floating point number, and converting 
it to
integer, or vice versa.  (In floating point notation 20E2 = 20*10^^2 = 2000).  
I had
thought that the (string) override meant to treat the actual value as a string, 
but in
this case it must be converting the (assumed) actual value to a string, and 
then comparing
the results.

This surprised me considerably as it is clear from the results I achieve in 
other
circumstances that the data is actually stored as a raw string.

$data is a variable format array, and when the original data is read each line 
is exploded
into a term of the data array: $data[][] = explode(';',$line[$i]);.  If I print 
the value
of the ident (or any other field) it is always shown as the original string, 
and when I
save an updated version of the data, each term of the data array is imploded 
into a line
of the data file in its original format. However if this value were actually 
converted to
a floating point number when it was entered I would have to specify a format 
before I
could write it out again, and as 20E2 is a rather  non-standard format it is 
most unlikely
that it would come out as this unaided. 

Is there any way to specify that each field is always to be treated as a string 
when I
originally explode the input file into the data array?  For someone brought up 
on rigidly
defined data types dynamic typing can be very confusing!

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



Re: [PHP] Comparing strings (revisited)

2009-05-27 Thread Clancy
On Mon, 25 May 2009 02:11:24 -0400, pa...@quillandmouse.com (Paul M Foster) 
wrote:

.
>
>This is why I originated a thread along these lines some time ago.  I
>sympathize with your pain, being a C programmer as well. Apparently, PHP
>plays fast and loose with types when doing == comparisons. And empty()
>has a really wild way of determining if something is "empty" (an integer
>0 is "empty"?). Which is why I originally asked if strcmp() was the
>preferred method of comparison for the list members.
>
>In any case, strcmp() does what you want and is the safest way to
>compare strings, which is what PHP passes around a lot (data comes out
>of databases as strings, comes back from forms as strings, etc.). And
>since most of the syntax and library functions of PHP are based on C
>paradigms, I'm guessing that the PHP strcmp() function is a thin veneer
>over the actual C function.

Thanks, Paul. 

I have done some more experimenting, and have a better handle on what is going 
on now, so
I don't think I will fall into any unexpected holes (apart from  by being 
careless!)

If you enter a value directly (eg. $a[0] = 000a; ) it tries to convert the 
input to a
number, and rejects any input it cannot convert (such as 000a). However if the 
value is
quoted it is stored internally as a string.

If the data is stored as elements of a string, and is exploded into an array no 
attempt is
made to interpret them, and they are stored as strings in their original form. 
They appear
to retain this form, but if they are compared with some other value the two 
values are
adjusted until they are of the same type, and then they are compared.  The 
results often
seem absurd at first glance. For example 000A < 2 < 10, but A > . I think 
the reason
for this is that if the values can be treated as numbers they are compared 
directly, but
otherwise the one with less characters is right padded with spaces, and then 
there are
compared as strings. Thus '000A' < '2   ', and 'A   ' > ''.

If the values are compared as strings (using strcmp or SORT_STRING) the results 
are
entirely logical if all the strings are of the same length. If the strings are 
of
different lengths the shorter one is again right padded (probably with spaces) 
and then
the two are compared.

These points are illustrated in the following test programs.

 Test 1. Values entered directly ';
$i = 0; $n = count ($a);
while ($i < $n)
{
echo ' $a['.$i.']: '.$a[$i].' = ';
$j = 0; while ($j < $n)
{
if (($i != $j) && ($a[$i] == $a[$j])) { echo $a[$j].', 
'; }
++$j;
}
++$i; echo '';
}

// Test two data:   
$ss = 2000;20e2;2.e3;2.E3;2.000e3;4000/2;4.0e3/2.0;20E2;;000A;A000;2;0010;
A;10;20;21';
$a = explode (';',$ss);

echo ' Test 2. Values exploded into array ';
$i = 0; $n = count ($a);
while ($i < $n)
{
echo ' $a['.$i.']: '.$a[$i].' = ';
$j = 0; while ($j < $n)
{
if (($i != $j) && ($a[$i] == $a[$j])) { echo $a[$j].', 
'; }
++$j;
}
++$i; echo '';
}

// Test 3.
$b = $a;
sort ($b, SORT_STRING);
sort ($a);
echo '   Sort normal.';
$i = 0; while ($i < $n)
{
echo '$a['.$i.'] = '.$a[$i].'';
++$i;
}

echo '   Sort string.';
$i = 0; while ($i < $n)
{
echo '$b['.$i.'] = '.$b[$i].'';
++$i;
}
?>
Results:

Test 1. Values entered directly. All values are converted to the simplest form 
on input.
 
$a[0]: 2000 = 2000, 2000, 2000, 2000, 2000, 2000, 20E2, 
$a[1]: 2000 = 2000, 2000, 2000, 2000, 2000, 2000, 20E2, 
$a[2]: 2000 = 2000, 2000, 2000, 2000, 2000, 2000, 20E2, 
$a[3]: 2000 = 2000, 2000, 2000, 2000, 2000, 2000, 20E2, 
$a[4]: 2000 = 2000, 2000, 2000, 2000, 2000, 2000, 20E2, 
$a[5]: 2000 = 2000, 2000, 2000, 2000, 2000, 2000, 20E2, 
$a[6]: 2000 = 2000, 2000, 2000, 2000, 2000, 2000, 20E2, 
$a[7]: 20E2 = 2000, 2000, 2000, 2000, 2000, 2000, 2000, 
$a[8]:  = , 
$a[9]:  = , 
$a[10]: 000A = 
 
Test 2. Values exploded into array. Values are preserved as strings until 
compared. 
 
$a[0]: 2000 = 20e2, 2.e3, 2.E3, 2.000e3, 20E2, 
$a[1]: 20e2 = 2000, 2.e3, 2.E3, 2.000e3, 20E2, 
$a[2]: 2.e3 = 2000, 20e2, 2.E3, 2.000e3, 20E2, 
$a[3]: 2.E3 = 2000, 20e2, 2.e3, 2.000e3, 20E2, 
$a[4]: 2.000e3 = 2000, 20e2, 2.e3, 2.E3, 20E2, 
$a[5]: 4000/2 = 
$a[6]: 4.0e3/2.0 = 
$a[7]: 20E2 = 2000, 20e2, 2.e3, 2.E3, 2.000e3, 
$a[8]:  = 
$a[9]: 000A = 
$a[10]: A000 = 
$a[11]: 2 = 
$a[12]: 0010 = 10, 
$a[13]: A = 
$a[14]: 10 = 0010, 
$a[15]: 20 = 
$a[16]: 21 = 
 
Test 3. Sort normal.
$a[0] = 000A
$a[1] = 2
$a[2] 

Re: [PHP] recipes anyone?

2009-05-30 Thread Clancy
On Sat, 30 May 2009 14:31:26 -0400, af.gour...@videotron.ca (PJ) wrote:


>> So, if corn is bad, eating it will get rid of it faster right? :p

>No it will turn you into a corn cob! ;-)

Which is why Christopher Columbus found the Americas uninhabited! ;-)


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



[PHP] Re: Directing form to different handlers?

2009-06-01 Thread Clancy
On Mon, 1 Jun 2009 12:53:31 +1000, angusm...@pobox.com ("Angus Mann") wrote:

>Hi all. I realize this is more an HTML question than PHP but I'm sure someone 
>here can help.
>
>I have several forms with lots (dozens) of text inputs. If the user presses 
>the "Update" button I want the form handled by "update.php" but if they press 
>"Delete" it needs to be handled by "delete.php" or "add.php" and so-on 
>depending on the button they press.
>
>But when establishing the form I can only have action="delete.php"> or "add.php" or whatever.
>
>Is there a way to direct the content of the form do a different handler 
>depending on the button?
>
>I know I can use javascript to direct to a constructed URL and append 
>?name=smith&address=hishouse&telephone=28376.and so on but this is not 
>practical when there are dozens of entriesthe URL becomes massive. I 
>prefer to use "POST" and then use PHP to extract the POST array.
>
>Any ideas?

I have two ways of handling this type of menu. In the first I have a form with 
a 'submit'
button, containing a number of radio buttons specifying different actions: 

/> Select names

The form can also contain check buttons specifying auxiliary options and text 
boxes
specifying input quantities.

My second type of menu looks very similar, but there is no form, and each 
option is a
small image (usually a yellow diamond). When you hit any button it invokes a 
new page
passing the new action, and related quantities, as parameters:

echo'';
echo ' Edit album page';

The same response handler handles both types of menu. It first looks for 
'action' in
$_GET, then it looks in $_POST, then it loads the appropriate handler as 
described below.

My standard program operates in four steps:

1. It checks for responses from the preceding page 

2. It processes them. To do this it has a table of response handlers, and 
includes a file
which handles the responses from the previous action.

3. It reads the new action, and includes the handler for this from a table of 
action
handlers. Quite often this is another menu which enables the user to specify 
additional
information. It is usually (but not necessarily) included inside the form for 
the main
menu, so that the specific fields appear above the normal foot. 

4. Finally it offers the same, or a different, menu for the user to specify the 
next
action. 

The advantage of the first type of menu is that it permits you to specify 
several
different values at the same time. For example one menu has a text input in 
which you can
enter a search string and different action buttons enabling you to specify to 
search
surnames only, search any name, or search in all possible fields. Its 
disadvantage is that
you have to select an action, then hit the submit button.

The advantage of the second type is that you only have to click one button, and 
it's
disadvantages are that you cannot specify auxiliary quantities, and you don't 
get a second
chance. 

Because the program is broken up in this way it is extremely flexible, and can 
completely
change its appearance and behaviour according to the task it is carrying out. 
The whole
program has a massive amount of code, but most of this is in the action and 
response
handlers, and because these are only included when they are needed, only a 
relatively
small amount of code is in memory at any given time.


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



[PHP] Time limit on recursive procedure?

2009-06-07 Thread Clancy
I have a recursive procedure, and I set the time limit each time I enter it:

function rec_scan($directory, ..)
{
set_time_limit (1);

if (is_dir($new_file))
{
rec_scan ($new_file, )
}

}


The way I read the manual, the timer should be reset each time I call 
rec_scanl, but I
seem to have to set a longer time limit than I would have anticipated, and I 
wonder if in
fact the original time limit still applies to the original invocation?


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



Re: [PHP] Time limit on recursive procedure?

2009-06-07 Thread Clancy
On Sun, 07 Jun 2009 13:04:20 +0200, p...@computer.org (Per Jessen) wrote:

>Clancy wrote:
>
>> I have a recursive procedure, and I set the time limit each time I
>> enter it:
>> 
>> function rec_scan($directory, ..)
>> {
>> set_time_limit (1);
>> 
>> if (is_dir($new_file))
>> {
>> rec_scan ($new_file, )
>> }
>> 
>> }
>> 
>> 
>> The way I read the manual, the timer should be reset each time I call
>> rec_scanl, 
>
>You keep calling it so as long as the execution time between each call
>is < 1 second, your script will keep going.
>
>/Per

Thanks.  That's what I thought. I'm using it to back up my working directory to 
another
drive, and a 3 second limit wasn't long enough, so one of the directories must 
take longer
than I expected to copy.


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



[PHP] Re: List files in a directory using filters and exclusions

2009-06-07 Thread Clancy
On Sat, 6 Jun 2009 21:39:15 -0400 (CDT), rsantama...@hab.uci.cu ("Rolando 
Santamaria
Maso") wrote:

>Hi PHP community, here I bring a very simple and interesting function that
>I made for a project, it's objetive is "to list path files in a directory
>with the possibility of using filters and exclusions".
>
>What do you think about?
>---
>
>function get_files($path, &$result,  Array $exclusions, Array $filters)
>{
>@$dir_content = scandir($path);
>   if ($dir_content)
>{
>$end= count($dir_content);
>$i  = 2;
>
>for ($i; $i < $end; $i++)
>{
>$path_and_element = $path.'/'.$dir_content[$i];
>if (array_search($path_and_element, $exclusions) === false)
>{
>if (array_search(substr($dir_content[$i],
>strlen($dir_content[$i]) - 4), $filters) !== false)
>{
>$result[] = $path_and_element;
>}
>
>   if (is_dir($path_and_element))
>{
>get_files($path_and_element, $result, $exclusions,
>$filters);
>}
>}
>   }
>   }
>}
>
>
>$path   = '/var/www';
>$result = array();
>$exclusions = array('/var/www/drupal', '/var/www/wp');
>$filters= array('.php');
>
>get_files($path, $result, $exclusions, $filters);
>
>echo "";
>print_r($result);
>die();

I have just written a recursive backup program, and used a slightly different 
exclusion
procedure:

$exclusions = array ('...drupal' => true, 'Images' =>'true',  );

if (!isset($exclusions[$file])) {  [copy file to backup ]  }

This looks simpler, and therefore quicker, but I suspect it is just putting the 
complexity
out of sight!




>
>
>Greetings
>

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



Re: [PHP] Re: SHOULD I NOT USE "ELSE" IN IF STATEMENTS....?

2009-06-09 Thread Clancy
On Tue, 09 Jun 2009 12:22:22 -0400, rob...@interjinn.com (Robert Cummings) 
wrote:

>Craige Leeder wrote:
>> I'm not sure I agree with NEVER using else. Sometimes else is a very 
>> logical way to organize code. However, it should not be used for data 
>> validation IE:
>> 
>> 
>> function myValidatorFunc($data) {
>>if (empty(data)) {
>>   return false;
>>} else {
>>   if (!is_numeric($data)) {
>>  return false;
>>   } else {
>> 
>>   }
>>}
>> }
>> 
>> 
>> It's all about how deep you nest your code, and keeping the flow clean. 
>> That code would be much more readable as such:
>> 
>> function myValidatorFunc($data) {
>>if (empty(data)) {
>>   throw new BadMethodCallException("Paramater data missing");
>>}
>>if (!is_numeric($data)) {
>>   throw new InvalidArgumentException("Paramater data should be an 
>> integer.");
>>}
>> }
>> 
>> See the difference?
>
>I believe the article was suggesting not ending a function that returns 
>a value with no return. So rather than return in the else, return 
>outside the else as the last expression of the function. This way it is 
>clear that the function returns a value.
>
>Contrast:
>
>
>function foo( $foo )
>{
> if( $foo )
> {
> return true;
> }
> else
> {
> return false;
> }
>}
>
>?>
>
>Versus:
>
>
>function foo( $foo )
>{
> if( $foo )
> {
> return true;
> }
>
> return false;
>}
>
>?>
>
>Personally, I also prefer the latter style.

I don't particularly like scattered returns, and prefer

Function foo;
{
result = false;
if (  ) { $result = 'yellow'; }
elseif (  ) { $result = 'blue'; }
return $result;
}


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



[PHP] Re: best way to properly build an include path *regardless* from where I am calling the include?

2009-07-06 Thread Clancy
On Sun, 5 Jul 2009 14:33:07 -0600, govinda.webdnat...@gmail.com (Govinda) wrote:

>I am confusing myself reading the docs just now.
>
>i.e.:
>include_path
>basename()
>and dirname()
>
>  I had thought from many months ago that
>
>would include
>somefile.php
>living in
>somedir
>regardless from where in the site structure I am calling it.
>
>Now it does not seem to be doing that.
>
>What is the safest (portable) way to properly build an include path  
>*regardless* from where in my site I am calling the include?
>If I understand right I can put includes in a dir/ specified by the  
>include_path setting, but I also want to know how to do this from just  
>within the root of my virtual server.

I have developed a quite sophisticated development system, which enables me to 
have
several different websites using the same software, and allows them all to 
share the same
utilities. I know some of you don't like some of the methods I use, but I think 
the
general idea is relevant to this discussion.

Each website has a local directory:
D:Websites/Website_1
D:Websites/Website_2
etc.
I also have an independent directory containing the common utilities for all 
the websites:
D:Utilities

Each website has one or more divisions, corresponding very roughly to photo 
albums. It
also has one directory containing the developmental version of the program, and 
a second
containing the working version of the program e.g.
Dev
Wkg
Album_1
etc.
The remote version of each website only has the directories:
Wkg
Utilities
Album_1
etc.

a new web page is invoked with the command: 
http://localhost/Website_1/index.php
or
http://www.corybas.com/index.php

If I want to ensure that a fresh version is loaded I add the parameter: ?new=1, 
and if I
want to invoke the developmental version, I followed this with the parameter:
&local_dir=Dev.

In either case the program index.php is loaded. This has the following code:


The main program begins by checking whether or not it is running on my home PC 
(using a
procedure which caused someone here to say 'Yukk'), but which seems to be both 
logically
sound and reliable.

*   ---
1.00  Check if running on home PC & set up defaults
---*/
$home = strtr(getcwd(),"\\","/");  // Ensure Home contains forward 
slashes
if (substr($home,0,2) == 'D:') 
{ 
$is_local = true; 
if ($local_dir == 'Dev') 
{ $util_dir = $local_dir; }
else { $util_dir = 'D:/Websites/Utilities'; }
} 
else 
{ $is_local = false; $util_dir = 'Utilities'; }

include ($util_dir.'/Std_utils.php');   // Load standard utilities
// Start real work:

If the parameter $is_local is set, I have access to a suite of editing 
facilities, and
other private areas. These are not present on the public copy, and there is 
nothing on any
of the menus to suggest that anything is missing.

The parameters $is_local and $local_dir are cached, so they only need to be 
specified when
the page is first loaded.

I never change the working directory (and it has never yet changed by itself), 
so I can
load anything in any subdirectory simply by specifying the local path. I also 
realised
while I was writing this that there is no real reason to have separate Wkg and 
Utilities
directories (other than that if I only had one version of the program for all 
local sites,
it would make the result of any bug that made it to the working version 
potentially that
much more serious).


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



[PHP] PHP: Writing to CD/DVD?

2009-07-23 Thread Clancy
Does anyone know of an extension/utility that will enable PHP to write backup 
files to a
CD/DVD?

Ideally I would like the CD to appear as 'just another drive'.


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



[PHP] Re: preg_match too greedy

2009-07-29 Thread Clancy
On Wed, 29 Jul 2009 13:42:23 -0400, p...@logi.ca (b) wrote:

>I'm trying to figure out how to test if a string matches *exactly* 
>another string, using a regexp pattern. 

If this is REALLY what you want to do, what is wrong with strcmp?


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



[PHP] PHP programming strategy

2009-08-01 Thread Clancy
Is anyone here interested in discussing programming strategy, or or know of a 
discussion
group which is interested in the subject?

The sorts of questions I am interested in are:

1. I have a highly variable program which always shows the same page, but which 
includes
different modules to give different results.  The various modules call on 
different
functions. Is it better to minimise memory by including only the functions 
actually
required, but increase the number of files included, or to bundle all the 
functions into
one file, thereby reducing the number of files included but increasing the size 
in memory?

2. As PHP is an interpreted program comments certainly increase the memory 
requirements,
and presumably they slow down the operation of the program. Would stripping out 
the
comments before uploading the production version give any visible improvement in
performance?


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



[PHP] Re: PHP programming strategy

2009-08-05 Thread Clancy
Thank you to all of you who have commented on this query. 

On the subject of comments, I feel that Larry Garfield settled this query by 
pointing out
that halving the size of a particular document gave a barely noticeable 
increase in speed.
Paul Foster pointed out the problem of maintenance, but if, as I do, you do your
development in-house, and then upload the working copies of the program, it 
would be
possible to strip out comments when you upload it. If you were really paranoid, 
this could
have the advantage that if somebody managed to steal your code from the server 
it would be
that much harder for them to understand. On the other hand the process of 
stripping out
the comments could potentially introduce new bugs, and I think this 
consideration would
outweigh anything else.

I have recently come to the conclusion that I should never consider anything 
completed
until I have analysed the HTML code for an actual page. It is amazing how badly 
mangled
tables and the like can be without producing any visible effect on the page, 
and on
several occasions I have found PHP error messages which were mixed up with the 
HTML in
such a way that they were not displayed at all. On at least one occasion this 
gave me the
clue to an otherwise baffling bug.  

I have also discovered that the process of analysing the HTML is made 
substantially
simpler by inserting HTML comments into the output; e.g. instead of

Echo '';
write
?> 


http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: PHP programming strategy

2009-08-05 Thread Clancy
On Wed, 5 Aug 2009 09:25:20 -0400, phps...@gmail.com (Bastien Koert) wrote:

>On Wed, Aug 5, 2009 at 8:02 AM, Ashley Sheridan 
>wrote:
>> On Wed, 2009-08-05 at 21:49 +1000, Clancy wrote:
>>> Thank you to all of you who have commented on this query.
>>>
>>> On the subject of comments, I feel that Larry Garfield settled this query 
>>> by pointing out
>>> that halving the size of a particular document gave a barely noticeable 
>>> increase in speed.
>>> Paul Foster pointed out the problem of maintenance, but if, as I do, you do 
>>> your
>>> development in-house, and then upload the working copies of the program, it 
>>> would be
>>> possible to strip out comments when you upload it. If you were really 
>>> paranoid, this could
>>> have the advantage that if somebody managed to steal your code from the 
>>> server it would be
>>> that much harder for them to understand. On the other hand the process of 
>>> stripping out
>>> the comments could potentially introduce new bugs, and I think this 
>>> consideration would
>>> outweigh anything else.
>>>
>>> I have recently come to the conclusion that I should never consider 
>>> anything completed
>>> until I have analysed the HTML code for an actual page. It is amazing how 
>>> badly mangled
>>> tables and the like can be without producing any visible effect on the 
>>> page, and on
>>> several occasions I have found PHP error messages which were mixed up with 
>>> the HTML in
>>> such a way that they were not displayed at all. On at least one occasion 
>>> this gave me the
>>> clue to an otherwise baffling bug.
>>>
>>> I have also discovered that the process of analysing the HTML is made 
>>> substantially
>>> simpler by inserting HTML comments into the output; e.g. instead of
>>>
>>>       Echo '';
>>> write
>>> ?>
>>> 
>>> >>
>>> 
>>> >>
>>> Unfortunately, for HTML readability, it is highly desirable not to indent 
>>> the code, and if
>>> you are trying to have nicely indented braces, this makes the PHP code that 
>>> much harder to
>>> interpret.
>>>
>>> And on the question of functions there is some virtue (primarily from the 
>>> point of view of
>>> maintenance) in not having individual files too large, so while it seems to 
>>> be the general
>>> consensus that splitting up functions into groups to give smaller files 
>>> will probably slow
>>> things down a bit, if they can be grouped into sets which are only loaded 
>>> in particular
>>> circumstances this would be worth doing.
>>>
>>>
>> Nested tables are the devils playthings!

I must be the devil, then.  I enjoy playing with them.  And if they're done 
right they
seem to work on every system I have tried them on.  Granted Dreamweaver design 
mode gets
its knickers in a knot if you nest them more than about 4 deep.

>>
>> Thanks,
>> Ash
>> http://www.ashleysheridan.co.uk
>>
>>
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>
>
>I would agree there...we have an app that allows users to create forms
>dynamically with a left and right panel section along with some full
>width plug-in. At a minimum this is built with three nested tables.
>Here's the really rotten part, the VP (original dev for the display
>code) screwed a table close up somewhere. A bug they found literally
>minutes before it when to prod at a client site, instead of giving me
>15 minutes to trace it down, they wrapped the entire table structure
>in another table to make it look pretty.

Clearly he didn't verify the HTML before he released the original version. ;-)
>
>Drives me mental as it produces lots a visual screw up when a certain
>pattern in the form elements is created

That's the joy of HTML errors - often the output will appear normal until you 
make some
minor, and apparently irrelevant, change, when it all goes haywire.


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



Re: [PHP] Re: PHP programming strategy

2009-08-06 Thread Clancy
On Thu, 06 Aug 2009 08:28:32 +0100, a...@ashleysheridan.co.uk (Ashley Sheridan) 
wrote:

...
>> >> Nested tables are the devils playthings!
>> 
>> I must be the devil, then.  I enjoy playing with them.  And if they're done 
>> right they
>> seem to work on every system I have tried them on.  Granted Dreamweaver 
>> design mode gets
>> its knickers in a knot if you nest them more than about 4 deep.
>> 
...
>> 
>> That's the joy of HTML errors - often the output will appear normal until 
>> you make some
>> minor, and apparently irrelevant, change, when it all goes haywire.
>> 
>> 
>That's not the only point. If you're on a slow connection you'll notice
>the issue. Some browsers only start displaying the page once all the
>layout data has been loaded. I've seen some sites with nesting levels of
>7 tables deep sometimes, and that's just a mess. I'm also unsure how
>text/speech/Braille browsers deal with complex table sites too.

I once watched a blind man go through one of my sites. I was apprehensive 
because I had no
made no attempt to achieve compatibility, and had not bothered with any alt = ''
declarations. The images were all in their own tables, and they all had titles, 
and he
said that because of this the site was relatively good.
>
>And tables shouldn't be used for layout, use CSS instead!...

I was talking to another web designer last night. He started life as a 
designer, and said
that he liked CSS because it was written by designers.  On the other hand I 
started life
as a programmer (well I really started life as an engineer), and I find CSS 
hard to
understand, and harder to write.  I can readily produce what I want with 
tables, but I
have no idea how I could achieve many of the results I get with CSS alone.

How, for example, could I otherwise achieved the following effect, which 
displays an image
with a border slightly darker than the background, and with the title and 
subtitle inside
the border?

   
  

  
  Yanni Nx 
  Sally Riordan Scholarship, 2007- 
  
  


(And the thing that really astounds me about CSS is that they never thought of 
putting in
constants. Instead of being able to specify a set of colours, and then simply 
quote them
in the CSS whenever they are needed, I have to specify them in PHP, and then 
encode them
into the CSS every time I use them, which is a real pain in the . The total 
lack of
diagnostics is another real pain.)


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



Re: [PHP] Re: PHP programming strategy

2009-08-07 Thread Clancy
On Fri, 07 Aug 2009 06:32:48 +0100, a...@ashleysheridan.co.uk (Ashley Sheridan) 
wrote:
...
>> How, for example, could I otherwise achieved the following effect, which 
>> displays an image
>> with a border slightly darker than the background, and with the title and 
>> subtitle inside
>> the border?
>> 
>>
>>   
>> 
>>   
>>   Yanni Nx 
>>   Sally Riordan Scholarship, 2007- 
>>   
>>   
>> 
>> 
 
>Well, your above example would just become:
>
>
>
>Yanni Nx 
>Sally Riordan Scholarship, 2007- 
>
>
>Notice how the amount of code has dropped immediately! 

Yes - all of 22 bytes!

> From there, you
>can use CSS to target whatever element you need to within the .pfm
>class.

As I already do with the table. The divs look interesting, but the tables work, 
so I  will
look into them when everything else is fixed - if I am still alive!

>The images on your site would not had had titles if you'd omitted alt
>tags. Where would the browser find them from to display to a blind
>person?

The titles (eg Yanni x, above).

>True, CSS does not have constants, but that is why you create them to
>cascade, so that elements inherit features from their parents. A bit
>like classes in programming, where everything is either inherited from
>the parent object (tag) or overridden with a new style.

I can completely change the color scheme and appearance by loading a new 
definition file,
but this would be much simpler if I did not have to encode the values into the 
CSS:

  #bodystyle {  
  font-family: "Times New Roman", Times, serif; color: #; 


>Also, if you're looking for diagnostics, give Firebug a try, as it
>really excels at this sort of thing. You can change styles on the fly
>from within the browser window, without needing to refresh the page!

Thanks, I will look into it.



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



Re: [PHP] Re: PHP programming strategy

2009-08-08 Thread Clancy
On Sat, 8 Aug 2009 07:53:42 -0400, tedd.sperl...@gmail.com (tedd) wrote:

>You don't need the width="210" height="300". For example, this works:
>
>
> 
> Yanni Nx 
> Sally Riordan Scholarship, 2007- 
>

I have read that if you omit the dimensions you will sometimes see the page 
reshuffle
itself as it loads, because the browser starts loading, then finds the 
dimensions are
incompatible with it's initial assumptions.  I don't know how serious a problem 
this is,
but  if the dimensions prevent it happening I am happy to provide them.
 In my scheme of things  has normal paragraph spacing, 'nrmltxtn' has zero 
spacing, and
'notetxtn' is a size smaller, also with zero line spacing.

>Also, if you use first-child, it could be taken down to:
>
>
> 
> Yanni Nx 
> Sally Riordan Scholarship, 2007- 
>

Except that line 2 is smaller than line 1.   In my scheme of things  has 
normal
paragraph spacing, 'nrmltxtn' has zero spacing, and 'notetxtn' is a size 
smaller, also
with zero line spacing.

I could redefine  &  for this class (provided I never want to use the 
normal values
in it), but there is something to be said for having a standard set of fonts, 
and always
knowing what I will get, rather than having  mean something different every 
time I use
it.

And, as others have pointed out, a few thousand bytes more or less is totally 
immaterial.


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



[PHP] FTP: File or directory?

2009-08-14 Thread Clancy
I have just got access to a new server, and am playing with upload/download 
procedures. I
looked in the root directory, and see several objects which I assume to be 
directories.
However I was surprised to find there does not appear to be any command to 
determine if an
object is a file or directory, either in PHP FTP or plain FTP.  I could try to 
change to
them, or download them, but this seems overkill.  Am I overlooking something 
obvious?

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



Re: [PHP] Re: File or directory?

2009-08-15 Thread Clancy
On Sat, 15 Aug 2009 10:33:07 +0100, a...@ashleysheridan.co.uk (Ashley Sheridan) 
wrote:

>On Sat, 2009-08-15 at 09:56 +0200, Ralph Deffke wrote:
>> can u upload ur own files ?
>> can u create a directory ?

Yes.

>> are u using a ftp client ?

No; I'm using straight PHP FTP
>> 
>> 
>> "Clancy"  wrote in message
>> news:kjhc85hpub7drihgappifphcboolt9u...@4ax.com...
>> > I have just got access to a new server, and am playing with
>> upload/download procedures. I
>> > looked in the root directory, and see several objects which I assume to be
>> directories.
>> > However I was surprised to find there does not appear to be any command to
>> determine if an
>> > object is a file or directory, either in PHP FTP or plain FTP.  I could
>> try to change to
>> > them, or download them, but this seems overkill.  Am I overlooking
>> something obvious?
>> 
>> 
>> 
>That answer doesn't seem to quite come close even to answering the op
>question.
>
>Have you looked at ftp_rawlist which returns a detailed list of files,
>along with their permissions and directory flags? Or you could use
>ftp_size to determine the size of a file, which should be nothing for a
>directory.

Thanks,

Yes; I found ftp_rawlist eventually, but I still haven't found a definition of 
the return
code, though I think I know most of it.

I guess that even a null file will hve some length?  I will probably use the 
leading 'd'
in the return code to test for directories..

(And I spent a long time trying to work out how 'drwxr-xr-x 2 riordan riordan 
512 Jul 31
06:40 cgi-bin' could contain lots of spaces, before I remembered that, as a 
result of one
of the weirder design decisions,  HTML suppresses trailing spaces.)


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



Re: [PHP] Re: File or directory?

2009-08-18 Thread Clancy
On Sun, 16 Aug 2009 23:24:05 -0600, george.lang...@shaw.ca (George Langley) 
wrote:

>is_dir()
>
>
>
>is_file()
>
>
>
I specifically asked about FTP under PHP.  As far as I can see neither of these 
references
have anything to do with FTP.


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



Re: [PHP] How to make sure that the target file to read is not under writing by others?

2009-08-19 Thread Clancy
On Wed, 19 Aug 2009 08:13:56 -0400, kyle.sm...@inforonics.com (Kyle Smith) 
wrote:

>Nitebirdz wrote:
>> On Wed, Aug 19, 2009 at 11:59:39AM +0100, Ashley Sheridan wrote:
>>   
>>>  
>>> No, what you're saying is 'use a log file in order to know when to look
>>> at another log file'. What would happen if you tried to access the
>>> control log file whilst it was in the process of being written to?
>>> Admittedly, you reduce your chances of failure because there is less
>>> data being written to the control log than the actual log, but the
>>> chance of reading incomplete data is still there!
>>>
>>> 
>>
>> WARNING: total newbie here.
>>
>> If I understood Arno correctly, he was recommending to implement
>> something like the old "/var/run/*pid" files in UNIX.  That way, you can
>> control whether or not the previous run is already done with the file
>> before you move on. 
>That is definitely the correct approach.  Have the script which copies 
>the log file touch a file called 'log_file.write' or some such.  When 
>it's done, remove the file.  Your PHP script should exit if that file 
>exists.  Of course, given the 30 minute cron cycle, it would then have 
>to wait until the next cycle.  Maybe run it more often.

I gather from this discussion that PHP allows two users to open a file for R/W? 
I had
assumed it wouldn't.

Anyway, how about:

$user = 'Fred'; $try_again = true;
If (!file_exists('Busy.txt'))
{
File_put_contents ('Busy.txt', $user);
If ($user == File_get_contents ('Busy.txt')
{
// Do what you have to
Unlink ('Busy.txt');
$try_again = false;
}
}
if ($try_again)
{
// Come back in 5 minutes
}

This has a theoretical weakness, in that Joe could check for Busy.txt in the 
interval
between your checking and writing it, and then write his copy after you had 
read your
copy. A moments delay between writing and re-reading would fix this.


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



[PHP] Invoking functions stored in a separate directory?

2009-08-21 Thread Clancy
I am developing an idea for a website engine which can be shared between 
several different
websites. Each website would have its own directory under a common root 
directory, and the
engine would be in a separate directory Engine:

Root
Website_1.com, Website_2.com, Engine

The website directories would each contain the design data for that website, 
consisting
basically of a mixture of text files and images. The various pages would be 
loaded by
loading index.php from the website root directory, and specifying a number of 
parameters
e.g.

http://www.corybas.com/index.php?path=Holidays&level=0&item=0

I have the minimum amount of code in index.php -- just enough to set some 
parameters to
identify the website, and then include ../Engine/Main_prog.php.  This in turn 
can include
any of a large number of other include files to carry out particular functions. 

I have the prototype working nicely on my PC, and on a stand-alone basis on a 
server, but
now I am trying to upload the multi-website version to a public host, and am 
encountering
a number of problems, mainly because I have never done any serious work with 
UNIX, and the
host support staff don't understand what I am trying to do.

The problems mainly relate to setting permissions to allow the website to 
access the
engine code. I only have a rough idea of how the permissions work, but I think 
that to
include engine code the website has to have read and execute rights to it, and 
I also
think that so far as the engine is concerned the website will count as 'other'. 
 (I can
easily arrange that all temporary files are written in the website directory.)

I suspect that rather than including the engine code in index.php, it would be 
better to
call functions in it, so that the website only required 'execute' rights, but I 
don't know
of any way to do this without having anything running permanently on the 
server. Can
anyone suggest how it can be done?



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



Re: [PHP] Invoking functions stored in a separate directory?

2009-08-22 Thread Clancy
On Fri, 21 Aug 2009 15:16:11 +0200, ak...@telkomsa.net ("Arno Kuhl") wrote:

>-Original Message-
>From: Clancy [mailto:clanc...@cybec.com.au] 
>Sent: 21 August 2009 01:26 PM
>To: php-general@lists.php.net
>Subject: [PHP] Invoking functions stored in a separate directory?
>
>I am developing an idea for a website engine which can be shared between
>several different websites. Each website would have its own directory under
>a common root directory, and the engine would be in a separate directory
>Engine:
>
>Root
>Website_1.com, Website_2.com, Engine
>
>The website directories would each contain the design data for that website,
>consisting basically of a mixture of text files and images. The various
>pages would be loaded by loading index.php from the website root directory,
>and specifying a number of parameters e.g.
>
>http://www.corybas.com/index.php?path=Holidays&level=0&item=0
>
>I have the minimum amount of code in index.php -- just enough to set some
>parameters to identify the website, and then include
>../Engine/Main_prog.php.  This in turn can include any of a large number of
>other include files to carry out particular functions. 
.
>
>Using include ../Engine/Main_prog.php won't work for you in a production
>environment. You need to create a path.php file that defines the absolute
>path to the engine for each website, and include it at the top of your
>website script. Then you can do something like:
>
>   include ENGINEPATH."Main_prog.php";

Thank you very much for this. It has at last provided the clue I was looking 
for, and
after far too long I have got a trivially simple demonstration working. One 
complication I
hadn't anticipated is that apparently I can only access functions in the 
include file, but
cannot execute any code in it. 

Thus when Halla.php read:

Eng_test_'.__LINE__.' Hallejuha!! : ';  ?>

and I included it:

$ok = define ('HOST_PATH','../Engine');
$ok = include (HOST_PATH.'/Halla.php');

nothing happened.

When Halla.php read:

Eng_test_'.__LINE__.' Hallejuha!! : '.$i.''; 
return $i; } ?>

and I included it:

$ok = define ('HOST_PATH','../Engine');
$ok = include (HOST_PATH.'/Halla.php');
$ok = halla (7);
echo ' Returned '.$ok'';

it did work.  I presume that this explains your next comment, in that I am 
neither reading
nor executing the code in the Include, so permissions don't come into it.

>You shouldn't really have permission problems as long as your website and
>engine are on the same server.  ...

>One other advantage it will give you for your particualr design is that you
>can have multiple engines per server (e.g. Engine1, Engine2, etc) so that
>you can bring one engine down for upgrade while still keeping sites running
>on the other engines.

Yes; I have got already got all that working.  Now I JUST have to convert my 
main program
into one big function!

Will I still be able to access $_GET & $_POST variables, and set up session 
variables from
inside this function? I guess I can declare them all GLOBAL?

Thanks, again,

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



Re: [PHP] Invoking functions stored in a separate directory?

2009-08-22 Thread Clancy
On Sat, 22 Aug 2009 20:37:17 +0930, robl...@aapt.net.au (David Robley) wrote:

>Clancy wrote:
>
>> $ok = include (HOST_PATH.'/Halla.php');
>
>Because you are assigning the result of the include to a variable. Try 
>
>include (HOST_PATH.'/Halla.php');
>
>and it will work as you expect. And similarly for 
>
>define ('HOST_PATH','../Engine');

Thanks. But no; that's not the answer.  'Include', like any other function, 
returns a
result; true if the operation was successful, and false if it failed. I was 
using this to
verify that the 'include' operation had been successful.

The more I thought about it last night, the more dissatisfied I became with the 
notions
that 'include' could work differently in different circumstances, and also that 
defining a
path could alter the way it worked.

I did some more tests this morning, and eventually established that my 
confusion was the
result of two different effects.

The first was that I find the PHP syntax rather picky,  and I rely on error 
messages to
alert me to my frequent errors, but apparently all error messages are turned 
off on the
remote system, and if anything is wrong all I get is a blank screen.

The second is that although I use Dreamweaver as an editor, and it has 
moderately good
colour coding which indicate most errors, I am partially red green colour blind 
and tend
not to notice the erroneous colours.

I repeated my tests this morning and eventually managed to establish that

i. there is no difference in the behaviour of include between the local 
and remote
systems, and

ii. contrary to Arno's advice, include ../Engine/Main_prog.php; works 
just the
same as include ENGINEPATH."Main_prog.php";

So now I can get on with uploading my program!

Thanks,

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




Re: [PHP] Rounding down?

2009-08-22 Thread Clancy
On Sat, 22 Aug 2009 14:02:58 +0100, a...@ashleysheridan.co.uk (Ashley Sheridan) 
wrote:

>On Sat, 2009-08-22 at 13:00 +0100, Richard Heyes wrote:
>> Hi,
>> 
>> > Is there a way to round down to the nearest 50?
>> >
>> > Example: Any number between 400 and 449 I would 400 to be displayed; 450 
>> > to 499 would be 450; 500 to 549 would be 500, etc?
>> 
>> Off the top of my head: divide the number by 50, run floor() on the
>> result, then times it by 50.
>> 
>> 1. 449 / 50 = 9.whatever
>> 2. floor(9.whatever) = 9
>> 3. 9 * 50 = 450
>> 
>> -- 
>> Richard Heyes
>> HTML5 graphing: RGraph - www.rgraph.net (updated 8th August)
>> Lots of PHP and Javascript code - http://www.phpguru.org
>> 
>
>It should be round() and not floor().
>
>449 / 50 = 8.98
>floor(8.98) = 8
>8 * 50 = 400
>
>round(8.98) = 9
>9 * 50 = 450
>
Definitely floor or int, not round.

Round 0.5-1.499 -> 1
Floor 1.0-1.999 -> 1

And if you really want to be accurate  you should allow for decimal conversion 
errors in
any operation involving floating point numbers.  Otherwise you cannot rely on 
(say) 50 not
being represented as 49.99, so that int or floor will give 49. In 
something like
this I usually add half of the precision I want to work to:

eg: $answer = 50* (int) (($x +0.5)/50);

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



[PHP] Re: how to strip empty lines out of a txt using preg_replace()

2009-09-04 Thread Clancy
On Fri, 4 Sep 2009 14:58:55 +0200, ralph_def...@yahoo.de ("Ralph Deffke") wrote:

>Hi all, I'm a bit under stress, maybe somebody knows the regex on a snap.
>using PHP_EOL would be great.

Here is a function which works for files pasted from browser screens:

function clean_up($dirty_file)
{
$contents = file_get_contents ($dirty_file);
if ($contents)
{
$c_array = explode ("\n", $contents);
$n = count($c_array);
$i = 0; $j = 0; while ($i < $n)
{
$line = trim($c_array[$i]);
if ($line != '')
{
$d_array[$j++] = $c_array[$i];
}
++$i;
}
$clean = implode ("\n",$d_array);
$data_file = file_put_contents($data_file, $clean);
}
}   

The virtue of this is you don't have to know, or care, what characters are on 
the blank
lines.


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



Re: [PHP] anyone interested in PHP? Call for moderator

2009-09-15 Thread Clancy
On Tue, 15 Sep 2009 13:47:06 +0100, a...@ashleysheridan.co.uk (Ashley Sheridan) 
wrote:

>On Tue, 2009-09-15 at 13:45 +0100, Richard Heyes wrote:
>> Hi,
>> 
>> > It is good to hear that they teach PHP in kindergarden these days.
>> 
>> I've heard it's soon to be part of the national curriculum here in the UK.
>> 
>> -- 
>> Richard Heyes
>> HTML5 graphing: RGraph - www.rgraph.net (updated 5th September)
>> Lots of PHP and Javascript code - http://www.phpguru.org
>> 
>I hope not, I'm not having some toddler doing me out of a job!

It's been known for years that the essential accessory for any piece of modern 
electronics
equipment is a 10-year-old boy!


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



Re: [PHP] moving to quad core

2009-09-15 Thread Clancy
On Tue, 15 Sep 2009 11:55:51 -0400, oorza...@gmail.com (Eddie Drapkin) wrote:

>On Tue, Sep 15, 2009 at 11:35 AM, Rahul S. Johari
> wrote:
>>

>the amount of cores, several dozen perhaps.  Like I said, I'm not too
>familiar with Apache, so I'd do some research and experimentation with
>the number of child workers to give Apache.

First we have people worrying about losing their jobs to kindergarten children, 
now we
have people recommending giving Apache child workers. Call out the RSPCC!


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