[PHP] Array mysteries

2007-03-11 Thread Otto Wyss

I want to convert weekdays with a simple function like

  $wdays = array
(0 = Sonntag
,1 = Montag
,2 = Dienstag
,3 = Mittwoch
,4 = Donnerstag
,5 = Freitag
,6 = Samstag
  );

  function convert_from_weekday ($weekday) {
return $wdays[$weekday];
  }

but this doesn't work while

  $wdays[$weekday];

outside of the function works correct. Has anybody an idea where's my 
mistake? I'd like to use a function so I may return substrings of the 
weekday.


O. Wyss

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



Re: [PHP] Array mysteries

2007-03-11 Thread Tijnema !

On 3/11/07, Otto Wyss [EMAIL PROTECTED] wrote:


I want to convert weekdays with a simple function like

  $wdays = array
(0 = Sonntag
,1 = Montag
,2 = Dienstag
,3 = Mittwoch
,4 = Donnerstag
,5 = Freitag
,6 = Samstag
  );

  function convert_from_weekday ($weekday) {
return $wdays[$weekday];
  }

but this doesn't work while

  $wdays[$weekday];

outside of the function works correct. Has anybody an idea where's my
mistake? I'd like to use a function so I may return substrings of the
weekday.

O. Wyss



$wdays is not defined inside the function, so you can do a few things:
- Pass the $wdays inside the function:
function convert_from_weekday ($weekday,$wdays) {
   return $wdays[$weekday];
 }
$day = convert_from_weekday(0,$wdays) // $day = Sonntag

- You could define $wdays inside the function
function convert_from_weekday ($weekday,$wdays) {
$wdays = array
   (0 = Sonntag
   ,1 = Montag
   ,2 = Dienstag
   ,3 = Mittwoch
   ,4 = Donnerstag
   ,5 = Freitag
   ,6 = Samstag
 );
   return $wdays[$weekday];
 }
$day = convert_from_weekday(0) // $day = Sonntag
- If you are working from inside a class, you could define $wdays as a
public variable.

I think this solved your problem, but don't hesitate to ask for more!

Tijnema




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




Re: [PHP] Array mysteries

2007-03-11 Thread Steve Edberg

At 9:51 AM +0100 3/11/07, Otto Wyss wrote:

I want to convert weekdays with a simple function like

  $wdays = array
(0 = Sonntag
,1 = Montag
,2 = Dienstag
,3 = Mittwoch
,4 = Donnerstag
,5 = Freitag
,6 = Samstag
  );

  function convert_from_weekday ($weekday) {
return $wdays[$weekday];
  }

but this doesn't work while

  $wdays[$weekday];

outside of the function works correct. Has anybody an idea where's 
my mistake? I'd like to use a function so I may return substrings of 
the weekday.





If the above is your exact code, then the problem is one of scope; 
move the $wdays declaration inside your convert_from_weekday() 
function.


However, you may want to investigate the formatting functions of date():

http://php.he.net/manual/en/function.date.php

Date should return names using the native locale; if you want to 
return date strings for other locales/languages, use setlocale() -


http://php.he.net/manual/en/function.setlocale.php

- and strftime() -

http://php.he.net/manual/en/function.strftime.php

I think you'll find your work has been at least partially done for 
you. And, see


http://php.he.net/manual/en/language.variables.scope.php

for more information on variable scope.

steve

--
+--- my people are the people of the dessert, ---+
| Steve Edberghttp://pgfsun.ucdavis.edu/ |
| UC Davis Genome Center[EMAIL PROTECTED] |
| Bioinformatics programming/database/sysadmin (530)754-9127 |
+ said t e lawrence, picking up his fork +

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



Re: [PHP] Separating HTML code from PHP code

2007-03-11 Thread Paul Novitski

At 3/10/2007 11:47 AM, Don Don wrote:
Hi all, i am building a system using php and am trying to separate 
the html codes from the php codes (i.e. placing them in separate 
files), I am from the java struts/spring background and seem to be 
finding it difficult doing that at the moment with php.


  I've got a registration form in html with the action pointing to 
a separate php file that will process the form when 
submitted.  when i want to output errors or messages, its currently 
being outputed in the resulting code generated by the php 
file.  What i would like is to return to the html page and display 
the messages there.



You can establish the HTML form as a template which your PHP script 
reads, modifies, and downloads to the browser.  For example, you 
could have a structure like this in a template:


p class=error@error@/p

form action=? type=post ...
...
/form

Read the template with file_get_contents(), use str_replace() to 
replace '@error@' with your current error message (or an empty 
string), and echo the template to the browser.


As others have said, one easy model for form processing is for the 
form to post to itself.  Here's how such a script might work:

___

initialize
if we are receiving a posted form
{
validate posted input
if no error
{
act on posted input
end
}
plug error message into form
}

display form
___

If the user submits the form, the logic begins again.


Paul Novitski
Juniper Webcraft Ltd.
http://juniperwebcraft.com 


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



Re: [PHP] Array mysteries

2007-03-11 Thread Otto Wyss

Steve Edberg wrote:

At 9:51 AM +0100 3/11/07, Otto Wyss wrote:


  function convert_from_weekday ($weekday) {
return $wdays[$weekday];
  }

If the above is your exact code, then the problem is one of scope; 
move the $wdays declaration inside your convert_from_weekday() 
function.



I'm more used to C++ than PHP, with global $wdays; it works.


However, you may want to investigate the formatting functions of date():

http://php.he.net/manual/en/function.date.php

Date should return names using the native locale; if you want to 
return date strings for other locales/languages, use setlocale() -


http://php.he.net/manual/en/function.setlocale.php



Thanks, I'll keep this in mind.

O. Wyss

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



Re: [PHP] Array mysteries

2007-03-11 Thread Satyam


- Original Message - 
From: Otto Wyss [EMAIL PROTECTED]

To: php-general@lists.php.net
Sent: Sunday, March 11, 2007 11:14 AM
Subject: Re: [PHP] Array mysteries



Steve Edberg wrote:

At 9:51 AM +0100 3/11/07, Otto Wyss wrote:


  function convert_from_weekday ($weekday) {
return $wdays[$weekday];
  }

If the above is your exact code, then the problem is one of scope; move 
the $wdays declaration inside your convert_from_weekday() function.



I'm more used to C++ than PHP, with global $wdays; it works.



Unless you are using the array elsewhere, it might be a good idea to put it 
inside the function so as to not polute the global namespace with variable 
names that have no need to be there.  In large applications, there is a 
non-trivial chance that someone else might use a variable by the same name 
and ruin your translation table.  It will be slightly slower, though.



As for the localization functions, you might see their effect in:

http://www.satyam.com.ar/int/setlocale/index.php?locale=de_DEsubmit=Aceptar

the input box allows you to enter different locales, the previous URL 
already has German selected.


Satyam


However, you may want to investigate the formatting functions of date():

http://php.he.net/manual/en/function.date.php

Date should return names using the native locale; if you want to return 
date strings for other locales/languages, use setlocale() -


http://php.he.net/manual/en/function.setlocale.php



Thanks, I'll keep this in mind.

O. Wyss

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



--
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.5.446 / Virus Database: 268.18.8/717 - Release Date: 10/03/2007 
14:25





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



[PHP] Value evaluation library

2007-03-11 Thread Sancar Saran
Hi,

Does anyone suggest to evaluation lib. 

I want to build sometin for check user posted values in php. If I remember 
correctly zend framework has someting like this...

So I cust need evaluation part. 

Is there any other good lib around there ?


Regards

Sancar

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



Re: [PHP] FW: looking for two remote functions

2007-03-11 Thread Myron Turner

Myron Turner wrote:

Tijnema ! wrote:

On 3/10/07, Németh Zoltán [EMAIL PROTECTED] wrote:

2007. 03. 10, szombat keltezéssel 12.42-kor Riyadh S. Alshaeiq ezt 
írta:
 Actually if right click on any file or folder on a machine you 
will see

that
 there are two values (Size on disk  Size). Files and folders are 
stored

on
 the disk in what is called clusters (a group of disk sectors). 
Size on

disk
 refers to the amount of cluster allocation a file is taking up, 
compared

to
 file size which is an actual byte count.

 As I mentioned before what I want is a function for getting the 
result

for
 the Size no for Size on Disk

okay then what about this?




Th

I wrote a small perl script which returns the bytes read when a file 
is read from the disk and it, too, agrees with the filesize and header 
sizes.  In Windows, the actual filesize is also returned by filesize 
and stat, not the size on disk (filesize uses stat).   Also, in the 
PHP manual, the fread example uses filesize to set the number of bytes 
to read:

  ||
Here's the perl script:
use strict;
use Fcntl;
sysopen (FH, index.htm, O_RDONLY);
my $buffer;
my $len = sysread(FH, $buffer, 8192,0);
print $len,\n;

If you are really anxious about size you can exec out to this script 
and get the file size.


--
  
Sorry the above version of the script was hard-coded for a small test 
file.  Here's the general version:


# get_len.pl
use strict;
use Fcntl;
sysopen (FH, $ARGV[0], O_RDONLY) or die \n;
my $buffer;
my $bytes_read = 0;
my $offset;
while($bytes_read = sysread(FH, $buffer, 8192, $offset)) {
$offset+=$bytes_read ;
}
print $offset,\n;

From an exec() you'd call it with the file name:
  perl get_len.pl filename
$len = exec(perl get_len.pl $filename);

_
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/

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



Re: [PHP] FW: looking for two remote functions

2007-03-11 Thread Tijnema !

On 3/11/07, Myron Turner [EMAIL PROTECTED] wrote:


Myron Turner wrote:
 Tijnema ! wrote:
 On 3/10/07, Németh Zoltán [EMAIL PROTECTED] wrote:

 2007. 03. 10, szombat keltezéssel 12.42-kor Riyadh S. Alshaeiq ezt
 írta:
  Actually if right click on any file or folder on a machine you
 will see
 that
  there are two values (Size on disk  Size). Files and folders are
 stored
 on
  the disk in what is called clusters (a group of disk sectors).
 Size on
 disk
  refers to the amount of cluster allocation a file is taking up,
 compared
 to
  file size which is an actual byte count.
 
  As I mentioned before what I want is a function for getting the
 result
 for
  the Size no for Size on Disk

 okay then what about this?


 Th

 I wrote a small perl script which returns the bytes read when a file
 is read from the disk and it, too, agrees with the filesize and header
 sizes.  In Windows, the actual filesize is also returned by filesize
 and stat, not the size on disk (filesize uses stat).   Also, in the
 PHP manual, the fread example uses filesize to set the number of bytes
 to read:
   ||
 Here's the perl script:
 use strict;
 use Fcntl;
 sysopen (FH, index.htm, O_RDONLY);
 my $buffer;
 my $len = sysread(FH, $buffer, 8192,0);
 print $len,\n;

 If you are really anxious about size you can exec out to this script
 and get the file size.

 --

Sorry the above version of the script was hard-coded for a small test
file.  Here's the general version:

# get_len.pl
use strict;
use Fcntl;
sysopen (FH, $ARGV[0], O_RDONLY) or die \n;
my $buffer;
my $bytes_read = 0;
my $offset;
while($bytes_read = sysread(FH, $buffer, 8192, $offset)) {
$offset+=$bytes_read ;
}
print $offset,\n;

From an exec() you'd call it with the file name:
  perl get_len.pl filename
$len = exec(perl get_len.pl $filename);



I'm not very familiar with PERL, so will this work with remote files?
As it seems that you are just reading from local hard drive...

Tijnema

_

Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/





Re: [PHP] Array mysteries

2007-03-11 Thread tedd

At 10:05 AM +0100 3/11/07, Tijnema ! wrote:


- You could define $wdays inside the function
function convert_from_weekday ($weekday,$wdays) {
$wdays = array
   (0 = Sonntag
   ,1 = Montag
   ,2 = Dienstag
   ,3 = Mittwoch
   ,4 = Donnerstag
   ,5 = Freitag
   ,6 = Samstag
 );
   return $wdays[$weekday];
 }
$day = convert_from_weekday(0) // $day = Sonntag


Tijnema:

That's also a shorter version of a simple switch statement.

I haven't thought of, or seen, that before -- thanks.

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

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



Re: [PHP] Array mysteries

2007-03-11 Thread Tijnema !

On 3/11/07, tedd [EMAIL PROTECTED] wrote:


At 10:05 AM +0100 3/11/07, Tijnema ! wrote:

- You could define $wdays inside the function
function convert_from_weekday ($weekday) {
$wdays = array
(0 = Sonntag
,1 = Montag
,2 = Dienstag
,3 = Mittwoch
,4 = Donnerstag
,5 = Freitag
,6 = Samstag
  );
return $wdays[$weekday];
  }
$day = convert_from_weekday(0) // $day = Sonntag

Tijnema:

That's also a shorter version of a simple switch statement.

I haven't thought of, or seen, that before -- thanks.

tedd



Yeah it is, but i just used moved his $wdays inside the function...

but well, there are ofcourse a lot of other options, as date(l) would also
return the day of the month :)

Tijnema

--

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



RE: [PHP] php and javascript error

2007-03-11 Thread tedd

At 5:28 PM +0100 3/7/07, [EMAIL PROTECTED] wrote:

  PS: If you want your code to validate, change the  to amp;  Add the

 closing /a tag too.
 PPS: It's advisable not to use the short tags, use ?php instead of ?

in such a cases I usually use ?= $var ? instead ?php echo $var ?. At
least it's shorter. :)

-afan


But, while it's shorter, it's still NOT advisable to use the shorter tags.

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

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



Re: [PHP] php and javascript error

2007-03-11 Thread Tijnema !

On 3/11/07, tedd [EMAIL PROTECTED] wrote:


At 5:28 PM +0100 3/7/07, [EMAIL PROTECTED] wrote:
   PS: If you want your code to validate, change the  to amp;  Add the
  closing /a tag too.
  PPS: It's advisable not to use the short tags, use ?php instead of ?
in such a cases I usually use ?= $var ? instead ?php echo $var ?. At
least it's shorter. :)

-afan

But, while it's shorter, it's still NOT advisable to use the shorter tags.

tedd



It does save space on your harddrive (Not much, but some :P)

and if it is for your own usage only, why not?

Tijnema

--

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

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




Re: [PHP] Save and Continue

2007-03-11 Thread tedd

At 10:51 AM -0500 3/7/07, Robert Cummings wrote:

On Wed, 2007-03-07 at 10:39 -0500, Dan Shirah wrote:


 then return to the same screen with the credit card
 information still populated


You should treat credit card information like a hot potato... get rid of
it as soon as possible. What happens if Johnny Forgetful forgets to log
out of his session on a public computer? Then Jenny Fastfingers jumps on
and notices the open session? Voila, Jenny Fastfingers just got Johnny
Forgetful's credit information.

Cheers,
Rob.


Rob :

Johnny Forgetful and Jenny Fastfingers? Where did you find them?

It sounds like characters out of an old Navy WWII Don't go on 
shore-leave without protection film.


:-)

tedd

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

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



Re: [PHP] php and javascript error

2007-03-11 Thread tedd

At 3:25 PM +0100 3/11/07, Tijnema ! wrote:

On 3/11/07, tedd mailto:[EMAIL PROTECTED][EMAIL PROTECTED] wrote:

At 5:28 PM +0100 3/7/07, mailto:[EMAIL PROTECTED][EMAIL PROTECTED] wrote:

  PS: If you want your code to validate, change the  to amp;  Add the

 closing /a tag too.
 PPS: It's advisable not to use the short tags, use ?php instead of ?

in such a cases I usually use ?= $var ? instead ?php echo $var ?. At
least it's shorter. :)

-afan


But, while it's shorter, it's still NOT advisable to use the shorter tags.

tedd


It does save space on your harddrive (Not much, but some :P)

and if it is for your own usage only, why not?

Tijnema


Tijnema:

Saves space? I would venture to say that if you took the inverse of 
the space that technique saves from a typical drive and turn it into 
dollars, we all (the entire world) could live the rest of our lives 
very comfortably. Another way to look at it, I would venture to say, 
if you took the total actual cost for the space everyone (all php 
programmers together) saved from a lifetime of work, you couldn't buy 
a cup of coffee with it. So, the old let's save space legacy 
concern doesn't mean squat anymore and it's meaning less squat each 
day.


opinion

It's a matter of style and consistency not to use short tags. Don't 
develop bad-habits when you can easily avoid them. Plus, while we 
develop code for ourselves, we seldom stay in that environment and 
when we do venture out, we often take those bad habits with us. Why 
do it wrong?


Also for me, adding php to a short tag is just a reminder of what 
language I'm currently using and that certainly doesn't inconvenience 
me a bit -. Besides, it provides me with some degree of comfort in 
that if I want to move my code publicly, or portions of it, I don't 
have to worry about past bad habits. After decades of programming, I 
have enough of those.


/opinion

Additionally, while I have not dealt with xml yet, I have read that 
there is a problem in dealing with xml if you use the php short tag 
regardless of if you're coding for yourself or not.


Cheers,

tedd

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

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



Re: [PHP] Array mysteries

2007-03-11 Thread tedd

At 3:05 PM +0100 3/11/07, Tijnema ! wrote:

On 3/11/07, tedd mailto:[EMAIL PROTECTED][EMAIL PROTECTED] wrote:

At 10:05 AM +0100 3/11/07, Tijnema ! wrote:


- You could define $wdays inside the function
function convert_from_weekday ($weekday) {
$wdays = array
   (0 = Sonntag
   ,1 = Montag
   ,2 = Dienstag
   ,3 = Mittwoch
   ,4 = Donnerstag
   ,5 = Freitag
   ,6 = Samstag
 );
   return $wdays[$weekday];
 }
$day = convert_from_weekday(0) // $day = Sonntag


Tijnema:

That's also a shorter version of a simple switch statement.

I haven't thought of, or seen, that before -- thanks.

tedd


Yeah it is, but i just used moved his $wdays inside the function...

but well, there are ofcourse a lot of other options, as date(l) 
would also return the day of the month :)


Tijnema



It's the technique and not the specific data thing I was addressing. 
When I'm confronted with a case condition, I typically use the switch 
statement. But, your solution provided me with another way to look at 
that.


Cheers,

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

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



Re: [PHP] FW: looking for two remote functions

2007-03-11 Thread Myron Turner


Tijnema ! wrote:


I'm not very familiar with PERL, so will this work with remote files?
As it seems that you are just reading from local hard drive...

Tijnema
It has to be on the machine from which the pages are being served. 

There have been several workable suggestions for different 
possibilities.  I think it would help if you gave the context for this. 
Are these pages on your own web site?   Are you downloading pages from 
third-party web sites using the browser?  Are you using the command line 
to download pages from other servers?


Here is a script which will get the headers for any file you can 
download from the web:


?php
$fp = fsockopen(www.example.org, 80, $errno, $errstr, 30);
if (!$fp) {
   echo $errstr ($errno)br /\n;
} else {
   $out = HEAD http://www.example.org/any_page.html / HTTP/1.1\r\n;
   $out .= Host: www.example.org\r\n;
   $out .= Connection: Close\r\n\r\n;

   fwrite($fp, $out);

   $header = ;
   while (!feof($fp)) {
   $header .=  fgets($fp, 256);
   }
   fclose($fp);
   echo $header;
}
?

In response you will get the headers:

HTTP/1.1 200 OK
Date: Sun, 11 Mar 2007 14:57:54 GMT
Server: Apache/2.0.51 (Fedora)
Last-Modified: Sun, 11 Mar 2007 13:00:03 GMT
ETag: 10eb0036-4d1-3c2bbac0
Accept-Ranges: bytes
Content-Length: 1233
Connection: close
Content-Type: text/plain; charset=UTF-8


This includes the content-length, which is what you want.  This script 
will download only the headers.


You will not get a content-length headers for php files, since they are 
in effect scripts and their length is not know in advance.  The same 
holds true for files which contain SSI.

_
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/

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



Re: [PHP] FW: looking for two remote functions

2007-03-11 Thread Tijnema !

On 3/11/07, Myron Turner [EMAIL PROTECTED] wrote:



Tijnema ! wrote:

 I'm not very familiar with PERL, so will this work with remote files?
 As it seems that you are just reading from local hard drive...

 Tijnema
It has to be on the machine from which the pages are being served.



He was looking for remote functions

There have been several workable suggestions for different

possibilities.  I think it would help if you gave the context for this.
Are these pages on your own web site?   Are you downloading pages from
third-party web sites using the browser?  Are you using the command line
to download pages from other servers?

Here is a script which will get the headers for any file you can
download from the web:

?php
$fp = fsockopen(www.example.org, 80, $errno, $errstr, 30);
if (!$fp) {
   echo $errstr ($errno)br /\n;
} else {
   $out = HEAD http://www.example.org/any_page.html / HTTP/1.1\r\n;
   $out .= Host: www.example.org\r\n;
   $out .= Connection: Close\r\n\r\n;

   fwrite($fp, $out);

   $header = ;
   while (!feof($fp)) {
   $header .=  fgets($fp, 256);
   }
   fclose($fp);
   echo $header;
}
?

In response you will get the headers:

HTTP/1.1 200 OK
Date: Sun, 11 Mar 2007 14:57:54 GMT
Server: Apache/2.0.51 (Fedora)
Last-Modified: Sun, 11 Mar 2007 13:00:03 GMT
ETag: 10eb0036-4d1-3c2bbac0
Accept-Ranges: bytes
Content-Length: 1233
Connection: close
Content-Type: text/plain; charset=UTF-8


This includes the content-length, which is what you want.  This script
will download only the headers.

You will not get a content-length headers for php files, since they are
in effect scripts and their length is not know in advance.  The same
holds true for files which contain SSI.



This is exactly what my script also did, get the content-length from the
header.
But i don't see what the actual problem is, there have been a lot of
solutions around here but they are all wrong?

Tijnema



_
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/

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




[PHP] Why won't this query go through?

2007-03-11 Thread Mike Shanley

Hi,

I am just not understanding what I could have possibly done wrong with 
this query. All of the variables are good, without special characters in 
any sense of the word... So why isn't it importing anything?


Thanks!

$q = INSERT INTO 
`visitors`(`username`,`password`,`email`,`firstname`,`lastname`,`birthdate`,`verifythis`)

   VALUES ('.$username.',
   '.md5($password1).',
   '.$email.',
   '.$firstname.',
   '.$lastname.',
   '.$birthdate.',
   '.$verifythis.');;
mysql_query($q);

--
Mike Shanley

~you are almost there~

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



Re: [PHP] FW: looking for two remote functions

2007-03-11 Thread Myron Turner
I think we've been talking to ourselves.  The guy with the original 
question seems to have folded his hand and gone home.



This is exactly what my script also did, get the content-length from the
header.
But i don't see what the actual problem is, there have been a lot of
solutions around here but they are all wrong?

Tijnema


--

_
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/

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



Re: [PHP] Why won't this query go through?

2007-03-11 Thread Tijnema !

On 3/11/07, Mike Shanley [EMAIL PROTECTED] wrote:


Hi,

I am just not understanding what I could have possibly done wrong with
this query. All of the variables are good, without special characters in
any sense of the word... So why isn't it importing anything?

Thanks!

$q = INSERT INTO

`visitors`(`username`,`password`,`email`,`firstname`,`lastname`,`birthdate`,`verifythis`)
   VALUES ('.$username.',
   '.md5($password1).',
   '.$email.',
   '.$firstname.',
   '.$lastname.',
   '.$birthdate.',
   '.$verifythis.');;
mysql_query($q);



* me is gettings crazy!!! ALWAYS USE THE MYSQL_ERROR COMMAND!
mysql_query($q);
becomes
mysql_query($q) or die(mysql_error());
then post the result of the error, or fix it by yourself when you know where
the error is.

Tijnema

--

Mike Shanley

~you are almost there~

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




Re: [PHP] Separating HTML code from PHP code

2007-03-11 Thread Michael Weaver

Hi Don,

I understand what you mean by separating out the code from the view  
or display. I ran into this issue with PHP several years ago and  
ended up writing a templating engine to allow for complete separation  
of the code from the display. The DynaCore System has been in  
development for the last 6 -7 years and is available at sourceforge  
(GPL):


http://www.sourceforge.net/projects/dynacore

as well as from

http://www.dynacore.org

The administrative area runs on the system and I would be more than  
willing to help you with the validation end of things if you are  
interested and decide to use the system.


Hope this helps...

Best regards,

Mike Weaver

--
Michael Weaver
Founder/Chief Facilitator
Dynamic Insight
Innovation through Communication

Tel: 1.814.574.4871
Email: [EMAIL PROTECTED]
Email: [EMAIL PROTECTED] (high-capacity)
AIM: dynamicinsight


The information in this email and subsequent attachments may contain
confidential information that is intended solely for the attention  
and use of
the named addressee(s). This message or any part thereof must not be  
disclosed,
copied, distributed or retained by any person without authorization  
from the
addressee. If you are not the intended recipient, please contact the  
sender by

reply email and destroy all copies of the original message.






Re: [PHP] Array mysteries

2007-03-11 Thread Edward Vermillion


On Mar 11, 2007, at 10:02 AM, tedd wrote:


At 3:05 PM +0100 3/11/07, Tijnema ! wrote:

On 3/11/07, tedd mailto:[EMAIL PROTECTED][EMAIL PROTECTED] wrote:

At 10:05 AM +0100 3/11/07, Tijnema ! wrote:


- You could define $wdays inside the function
function convert_from_weekday ($weekday) {
$wdays = array
   (0 = Sonntag
   ,1 = Montag
   ,2 = Dienstag
   ,3 = Mittwoch
   ,4 = Donnerstag
   ,5 = Freitag
   ,6 = Samstag
 );
   return $wdays[$weekday];
 }
$day = convert_from_weekday(0) // $day = Sonntag


Tijnema:

That's also a shorter version of a simple switch statement.

I haven't thought of, or seen, that before -- thanks.

tedd


Yeah it is, but i just used moved his $wdays inside the function...

but well, there are ofcourse a lot of other options, as date(l)  
would also return the day of the month :)


Tijnema



It's the technique and not the specific data thing I was  
addressing. When I'm confronted with a case condition, I typically  
use the switch statement. But, your solution provided me with  
another way to look at that.


Cheers,

tedd


But what's the cost of this in a loop, rebuilding the array each  
time, as compared to a switch statement? Just another thought...


Ed

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



Re: [PHP] Save and Continue

2007-03-11 Thread Robert Cummings
On Sun, 2007-03-11 at 10:31 -0400, tedd wrote:
 At 10:51 AM -0500 3/7/07, Robert Cummings wrote:
 On Wed, 2007-03-07 at 10:39 -0500, Dan Shirah wrote:
 
   then return to the same screen with the credit card
   information still populated
 
 You should treat credit card information like a hot potato... get rid of
 it as soon as possible. What happens if Johnny Forgetful forgets to log
 out of his session on a public computer? Then Jenny Fastfingers jumps on
 and notices the open session? Voila, Jenny Fastfingers just got Johnny
 Forgetful's credit information.
 
 Cheers,
 Rob.
 
 Rob :
 
 Johnny Forgetful and Jenny Fastfingers? Where did you find them?
 
 It sounds like characters out of an old Navy WWII Don't go on 
 shore-leave without protection film.

*lol* I just made them up. But I do remember the process strangely
enough... Forst off I had John Doe on my mine, then Johnny Mnemonic
passed through my head and so I made it appropriate to the example at
hand by making it Johnny Forgetful, next Jane is the usual the feminine
version of John Doe, so then I had Janey Fastfingers, but it didn't ring
quite right so I changed it to Jenny to sound more like Johnny ;)

Why I remember the process whereby I arrived at Johnny Forgetful and
Jenny Fastfingers is anyone's guess :)

Cheers,
Rob.
-- 
..
| InterJinn Application Framework - http://www.interjinn.com |
::
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for   |
| creating re-usable components quickly and easily.  |
`'

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



Re: [PHP] My help with adding captcha

2007-03-11 Thread Tijnema !

On 3/11/07, Joker7 [EMAIL PROTECTED] wrote:


Hi- as you know I have been working on adding a captcha image to my
guestbook.
Well I have managed to get a very basic one working ;) but !I have been
trying to get one that would make it more easy to use ,I have it working
until I add it to my form.

My form use's print see below and I need to add this to it:


img style=vertical-align: middle src=?php echo
captchaImgUrl()?input name=captcha size=8/
a href=?php echo captchaWavUrl()?Listen To This/a



Did you forget to add the semi-colom??

img style=vertical-align: middle src=?php echo
captchaImgUrl();?input name=captcha size=8/
a href=?php echo captchaWavUrl();?Listen To This/a

Tijnema




Any tip would be welcome.
Chris

{
print table border='0' cellpadding='6'trtd class='book';
print form method='post' action='try.php' name='form';
print p class=contentName:/p input type='text' name='name'
size='40'br;
print p class=contentCountry:/pinput type='text' name='country'
size='40'br;
print p class=contentHomepage/pinput type='text' name='homepage'
value='http://' size='40'br;
print p class=contentE-mail:/pinput type='text' name='email'
size='40'br;
print p class=contentAim:/pinput type='text' name='aim'
size='40'br;
print p class=contentICQ:/pinput type='text' name='icq'
size='40'br;
print p class=contentYahoo:/pinput type='text' name='yim'
size='40'br;
print p class=contentMSN:/pinput type='text' name='msn'
size='40'br;
print p class=contentComment:/p;
print textarea rows='6' name='comment' cols='45'/textareabr;

I need to add it here!!

print input type='submit' name='submit' value='submit';
print /formbr;
print p class='big'Clickable Smilies/p;
print a onClick=\addSmiley(':)')\img src='images/smile.gif'/a
;
print a onClick=\addSmiley(':(')\img src='images/sad.gif'/a
;
print a onClick=\addSmiley(';)')\img src='images/wink.gif'/a
;
print a onClick=\addSmiley(';smirk')\img
src='images/smirk.gif'/a ;
print a onClick=\addSmiley(':blush')\img
src='images/blush.gif'/a ;
print a onClick=\addSmiley(':angry')\img
src='images/angry.gif'/a ;
print a onClick=\addSmiley(':shocked')\img
src='images/shocked.gif'/a ;
print a onClick=\addSmiley(':cool')\img
src='images/cool.gif'/a ;
print a onClick=\addSmiley(':ninja')\img
src='images/ninja.gif'/a ;
print a onClick=\addSmiley('(heart)')\img
src='images/heart.gif'/a ;
print a onClick=\addSmiley('(!)')\img
src='images/exclamation.gif'/a ;
print a onClick=\addSmiley('(?)')\img
src='images/question.gif'/abr;
print a onclick=\addSmiley(':{blink}')\img
src='images/winking.gif'/a;
print A onclick=\addSmiley('{clover}')\img
src='images/clover.gif'/a;
print a onclick=\addSmiley(':[glasses]')\img
src='images/glasses.gif'/a;
print a onclick=\addSmiley(':[barf]')\img
src='images/barf.gif'/a;
print a onclick=\addSmiley(':[reallymad]')\img
src='images/mad.gif'/a;
print script language=\JavaScript\ type=\text/javascript\\n;
print function addSmiley(textToAdd)\n;
print {\n;
print document.form.comment.value += textToAdd;;
print document.form.comment.focus();\n;
print }\n;
print /script\n;
print brbr;
print p class='big'A href=\javascript:popWin('bbcode.php',400,
5)\BBCode instructions/a/p;
  }


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




[PHP] Stream Functions

2007-03-11 Thread ccspencer
Hello, 


I have been trying to get the stream functions to work in PHP.  While
undoubtedly my problems are due to ignorance I'd appreciate anything
helpful anyone would care to say that might alleviate that ignorance.
Basically, I have just been trying to get the examples given in the
manual to work for the unix domain.  I created the two files below
and hit them with my browser. 


servertest.php
--
?php
$socket = stream_socket_server(unix://testsock, $errno, $errstr, 
STREAM_SERVER_BIND);

if (!$socket) {
  echo ERROR: $errno - $errstrbr /\n;
} else {
while ($conn = stream_socket_accept($socket)) {
  fwrite($conn, date(D M j H:i:s Y\r\n));
  fclose($conn);
}
fclose($socket);
}
? 


This appears to be working.  It creates the socket file in the file
system.  Then after a long delay, which I presume is waiting for a
client request, it returns the following. 


Warning: stream_socket_accept() [function.stream-socket-accept]:
accept failed: Operation timed out in
/usr/local/www/data/servertest.php on line 6 

Afterward the socket file is left on the file system. 


socktest.php

?php
$fp = stream_socket_client(unix://testsock, $errno, $errstr);
if (!$fp) {
  echo ERROR: $errno - $errstrbr /\n;
} else {
  fwrite($fp, \n);
  echo fread($fp, 26);
  fclose($fp);
}
? 


Running this while the server is waiting (or after it has given
up) produces the following. 


Warning: stream_socket_client() [function.stream-socket-client]:
unable to connect to unix://testsock (Connection refused) in
/usr/local/www/data/socktest.php on line 2
ERROR: 61 - Connection refused 


If the socket is removed the message changes to file not found
and if the permissions are changed the message changes to permission
denied.  So the program seems to be finding the socket and have
permission to access it. 

Can anyone suggest why the connection might be refused? 

Best, 

Craig 



--
- Virtual Phonecards - Instant Pin by Email  -
-   Large Selection - Great Rates-
- http://speedypin.com/?aff=743co_branded=1 -
-- 



**
**
*  Craig Spencer *
*  [EMAIL PROTECTED]*
**
**

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



Re: [PHP] Array mysteries

2007-03-11 Thread Larry Garfield
On Sunday 11 March 2007 12:02 pm, Edward Vermillion wrote:
  At 10:05 AM +0100 3/11/07, Tijnema ! wrote:
  - You could define $wdays inside the function
  function convert_from_weekday ($weekday) {
  $wdays = array
 (0 = Sonntag
 ,1 = Montag
 ,2 = Dienstag
 ,3 = Mittwoch
 ,4 = Donnerstag
 ,5 = Freitag
 ,6 = Samstag
   );
 return $wdays[$weekday];
   }
  $day = convert_from_weekday(0) // $day = Sonntag

*snip*

  It's the technique and not the specific data thing I was
  addressing. When I'm confronted with a case condition, I typically
  use the switch statement. But, your solution provided me with
  another way to look at that.
 
  Cheers,
 
  tedd

 But what's the cost of this in a loop, rebuilding the array each
 time, as compared to a switch statement? Just another thought...

 Ed

That's why you can just declare it static:

function convert_from_weekday ($weekday) {
static $wdays = array(
0 = Sonntag,
1 = Montag,
2 = Dienstag,
3 = Mittwoch,
4 = Donnerstag,
5 = Freitag,
6 = Samstag
);
return $wdays[$weekday];
}

And then it's only ever defined once, and the lookup is just an array-key 
search that happens down in the engine.  I do this sort of mapping all the 
time.  

-- 
Larry Garfield  AIM: LOLG42
[EMAIL PROTECTED]   ICQ: 6817012

If nature has made any one thing less susceptible than all others of 
exclusive property, it is the action of the thinking power called an idea, 
which an individual may exclusively possess as long as he keeps it to 
himself; but the moment it is divulged, it forces itself into the possession 
of every one, and the receiver cannot dispossess himself of it.  -- Thomas 
Jefferson

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



Re: [PHP] Array mysteries

2007-03-11 Thread tedd

At 12:02 PM -0500 3/11/07, Edward Vermillion wrote:

On Mar 11, 2007, at 10:02 AM, tedd wrote:


At 3:05 PM +0100 3/11/07, Tijnema ! wrote:

On 3/11/07, tedd mailto:[EMAIL PROTECTED][EMAIL PROTECTED] wrote:

At 10:05 AM +0100 3/11/07, Tijnema ! wrote:


- You could define $wdays inside the function
function convert_from_weekday ($weekday) {
$wdays = array
   (0 = Sonntag
   ,1 = Montag
   ,2 = Dienstag
   ,3 = Mittwoch
   ,4 = Donnerstag
   ,5 = Freitag
   ,6 = Samstag
 );
   return $wdays[$weekday];
 }
$day = convert_from_weekday(0) // $day = Sonntag


Tijnema:

That's also a shorter version of a simple switch statement.

I haven't thought of, or seen, that before -- thanks.

tedd


Yeah it is, but i just used moved his $wdays inside the function...

but well, there are ofcourse a lot of other options, as date(l) 
would also return the day of the month :)


Tijnema



It's the technique and not the specific data thing I was 
addressing. When I'm confronted with a case condition, I typically 
use the switch statement. But, your solution provided me with 
another way to look at that.


Cheers,

tedd


But what's the cost of this in a loop, rebuilding the array each 
time, as compared to a switch statement? Just another thought...






Ed

It's just another way to look at a possible solution.

As for the cost, what are we talking about? I doubt that a typical 
application would show any discernable difference in execution times.


One could test this easy enough by running both through 50k loops, 
but even then I doubt that the times would be that much different -- 
but I may be wrong, been there before.


Cheers,

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

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



[PHP] PEAR not found

2007-03-11 Thread rwhartung

Hi all,
 I have a new install and am trying to get PEAR working - MDB2 to be exact.

I have modified /etc/php.ini to have the following

 include_path = .:/php/includes:/usr/share/pear

phpinfo() reports the directive --includedir=/usr/include

I can confirm that MDB2.php exists in that directory.
httpd has been restarted. I have literally copied the examples form the 
PEAR docs and I am using a postgresql backend using the bpsimple 
database that I can access with no problems with pg_connect() from a php 
script.


When using PEAR::MDB2 all I get is MDB2 Error:not found.

So it seems that the directoyr is  not being read.  Ideas of where to 
start looking?  All pointers appreciated.


Bob

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



Re: [PHP] Array mysteries

2007-03-11 Thread Edward Vermillion


On Mar 11, 2007, at 1:59 PM, tedd wrote:


At 12:02 PM -0500 3/11/07, Edward Vermillion wrote:

On Mar 11, 2007, at 10:02 AM, tedd wrote:


At 3:05 PM +0100 3/11/07, Tijnema ! wrote:
On 3/11/07, tedd mailto:[EMAIL PROTECTED][EMAIL PROTECTED]  
wrote:


At 10:05 AM +0100 3/11/07, Tijnema ! wrote:


- You could define $wdays inside the function
function convert_from_weekday ($weekday) {
$wdays = array
   (0 = Sonntag
   ,1 = Montag
   ,2 = Dienstag
   ,3 = Mittwoch
   ,4 = Donnerstag
   ,5 = Freitag
   ,6 = Samstag
 );
   return $wdays[$weekday];
 }
$day = convert_from_weekday(0) // $day = Sonntag


Tijnema:

That's also a shorter version of a simple switch statement.

I haven't thought of, or seen, that before -- thanks.

tedd


Yeah it is, but i just used moved his $wdays inside the function...

but well, there are ofcourse a lot of other options, as date 
(l) would also return the day of the month :)


Tijnema



It's the technique and not the specific data thing I was  
addressing. When I'm confronted with a case condition, I  
typically use the switch statement. But, your solution provided  
me with another way to look at that.


Cheers,

tedd


But what's the cost of this in a loop, rebuilding the array each  
time, as compared to a switch statement? Just another thought...






Ed

It's just another way to look at a possible solution.

As for the cost, what are we talking about? I doubt that a  
typical application would show any discernable difference in  
execution times.


One could test this easy enough by running both through 50k loops,  
but even then I doubt that the times would be that much different  
-- but I may be wrong, been there before.


Cheers,

tedd


I don't know if there would be any difference either, which is why it  
was a question.


Although Larry's suggestion of making the array static is something I  
hadn't thought of.


Overall it is an interesting concept to use an array instead of a  
switch, and I do wonder at what point, if any, that the two would  
start to diverge resource-wise.


Would the array lookup be faster for a lesser-used option/key in a  
situation where there were quite a few options? (you wouldn't have to  
go through the whole switch to get to the option at the end (?) or  
would you? I have no idea how that all works internally)


Ed

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



Re: [PHP] Array mysteries

2007-03-11 Thread Satyam


- Original Message - 
From: Edward Vermillion [EMAIL PROTECTED]

To: tedd [EMAIL PROTECTED]
Cc: Tijnema ! [EMAIL PROTECTED]; php-general@lists.php.net
Sent: Sunday, March 11, 2007 8:57 PM
Subject: Re: [PHP] Array mysteries




On Mar 11, 2007, at 1:59 PM, tedd wrote:


At 12:02 PM -0500 3/11/07, Edward Vermillion wrote:

On Mar 11, 2007, at 10:02 AM, tedd wrote:


At 3:05 PM +0100 3/11/07, Tijnema ! wrote:

On 3/11/07, tedd mailto:[EMAIL PROTECTED][EMAIL PROTECTED]  wrote:

At 10:05 AM +0100 3/11/07, Tijnema ! wrote:


- You could define $wdays inside the function
function convert_from_weekday ($weekday) {
$wdays = array
   (0 = Sonntag
   ,1 = Montag
   ,2 = Dienstag
   ,3 = Mittwoch
   ,4 = Donnerstag
   ,5 = Freitag
   ,6 = Samstag
 );
   return $wdays[$weekday];
 }
$day = convert_from_weekday(0) // $day = Sonntag


Tijnema:

That's also a shorter version of a simple switch statement.

I haven't thought of, or seen, that before -- thanks.

tedd


Yeah it is, but i just used moved his $wdays inside the function...

but well, there are ofcourse a lot of other options, as date (l) 
would also return the day of the month :)


Tijnema



It's the technique and not the specific data thing I was  addressing. 
When I'm confronted with a case condition, I  typically use the switch 
statement. But, your solution provided  me with another way to look at 
that.


Cheers,

tedd


But what's the cost of this in a loop, rebuilding the array each  time, 
as compared to a switch statement? Just another thought...






Ed

It's just another way to look at a possible solution.

As for the cost, what are we talking about? I doubt that a  typical 
application would show any discernable difference in  execution times.


One could test this easy enough by running both through 50k loops,  but 
even then I doubt that the times would be that much different  -- but I 
may be wrong, been there before.


Cheers,

tedd


I don't know if there would be any difference either, which is why it  was 
a question.


Although Larry's suggestion of making the array static is something I 
hadn't thought of.


Overall it is an interesting concept to use an array instead of a  switch, 
and I do wonder at what point, if any, that the two would  start to 
diverge resource-wise.


Would the array lookup be faster for a lesser-used option/key in a 
situation where there were quite a few options? (you wouldn't have to  go 
through the whole switch to get to the option at the end (?) or  would 
you? I have no idea how that all works internally)


Yes, you would.  It goes sequentially through each case:.  The array, on the 
other hand, uses a hashing algorithm so it should be about even no matter 
which option you pick.


Satyam

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



Re: [PHP] Array mysteries

2007-03-11 Thread Tijnema !

On 3/11/07, Satyam [EMAIL PROTECTED] wrote:



- Original Message -
From: Edward Vermillion [EMAIL PROTECTED]
To: tedd [EMAIL PROTECTED]
Cc: Tijnema ! [EMAIL PROTECTED]; php-general@lists.php.net
Sent: Sunday, March 11, 2007 8:57 PM
Subject: Re: [PHP] Array mysteries



 On Mar 11, 2007, at 1:59 PM, tedd wrote:

 At 12:02 PM -0500 3/11/07, Edward Vermillion wrote:
 On Mar 11, 2007, at 10:02 AM, tedd wrote:

 At 3:05 PM +0100 3/11/07, Tijnema ! wrote:
 On 3/11/07, tedd mailto:[EMAIL PROTECTED][EMAIL PROTECTED]
  wrote:

 At 10:05 AM +0100 3/11/07, Tijnema ! wrote:

 - You could define $wdays inside the function
 function convert_from_weekday ($weekday) {
 $wdays = array
(0 = Sonntag
,1 = Montag
,2 = Dienstag
,3 = Mittwoch
,4 = Donnerstag
,5 = Freitag
,6 = Samstag
  );
return $wdays[$weekday];
  }
 $day = convert_from_weekday(0) // $day = Sonntag

 Tijnema:

 That's also a shorter version of a simple switch statement.

 I haven't thought of, or seen, that before -- thanks.

 tedd


 Yeah it is, but i just used moved his $wdays inside the function...

 but well, there are ofcourse a lot of other options, as date (l)
 would also return the day of the month :)

 Tijnema


 It's the technique and not the specific data thing I was  addressing.
 When I'm confronted with a case condition, I  typically use the
switch
 statement. But, your solution provided  me with another way to look
at
 that.

 Cheers,

 tedd

 But what's the cost of this in a loop, rebuilding the array
each  time,
 as compared to a switch statement? Just another thought...




 Ed

 It's just another way to look at a possible solution.

 As for the cost, what are we talking about? I doubt that a  typical
 application would show any discernable difference in  execution times.

 One could test this easy enough by running both through 50k loops,  but
 even then I doubt that the times would be that much different  -- but I
 may be wrong, been there before.

 Cheers,

 tedd

 I don't know if there would be any difference either, which is why
it  was
 a question.

 Although Larry's suggestion of making the array static is something I
 hadn't thought of.

 Overall it is an interesting concept to use an array instead of
a  switch,
 and I do wonder at what point, if any, that the two would  start to
 diverge resource-wise.

 Would the array lookup be faster for a lesser-used option/key in a
 situation where there were quite a few options? (you wouldn't have
to  go
 through the whole switch to get to the option at the end (?) or  would
 you? I have no idea how that all works internally)

Yes, you would.  It goes sequentially through each case:.  The array, on
the
other hand, uses a hashing algorithm so it should be about even no matter
which option you pick.

Satyam



PHP is always fast, as long as you are not trying to do this 50k times, does
it make sense if a function takes 0.0056 or 0.0057 seconds to
execute?
I don't think so, so that means this is all going about users preference.

Tijnema


Re: [PHP] Array mysteries

2007-03-11 Thread Robert Cummings
On Sun, 2007-03-11 at 21:41 +0100, Satyam wrote:
 - Original Message - 
 From: Edward Vermillion [EMAIL PROTECTED]
 To: tedd [EMAIL PROTECTED]
 Cc: Tijnema ! [EMAIL PROTECTED]; php-general@lists.php.net
 Sent: Sunday, March 11, 2007 8:57 PM
 Subject: Re: [PHP] Array mysteries
 
 
 
  On Mar 11, 2007, at 1:59 PM, tedd wrote:
 
  At 12:02 PM -0500 3/11/07, Edward Vermillion wrote:
  On Mar 11, 2007, at 10:02 AM, tedd wrote:
 
  At 3:05 PM +0100 3/11/07, Tijnema ! wrote:
  On 3/11/07, tedd mailto:[EMAIL PROTECTED][EMAIL PROTECTED]  wrote:
 
  At 10:05 AM +0100 3/11/07, Tijnema ! wrote:
 
  - You could define $wdays inside the function
  function convert_from_weekday ($weekday) {
  $wdays = array
 (0 = Sonntag
 ,1 = Montag
 ,2 = Dienstag
 ,3 = Mittwoch
 ,4 = Donnerstag
 ,5 = Freitag
 ,6 = Samstag
   );
 return $wdays[$weekday];
   }
  $day = convert_from_weekday(0) // $day = Sonntag
 
  Tijnema:
 
  That's also a shorter version of a simple switch statement.
 
  I haven't thought of, or seen, that before -- thanks.
 
  tedd
 
 
  Yeah it is, but i just used moved his $wdays inside the function...
 
  but well, there are ofcourse a lot of other options, as date (l) 
  would also return the day of the month :)
 
  Tijnema
 
 
  It's the technique and not the specific data thing I was  addressing. 
  When I'm confronted with a case condition, I  typically use the switch 
  statement. But, your solution provided  me with another way to look at 
  that.
 
  Cheers,
 
  tedd
 
  But what's the cost of this in a loop, rebuilding the array each  time, 
  as compared to a switch statement? Just another thought...
 
 
 
 
  Ed
 
  It's just another way to look at a possible solution.
 
  As for the cost, what are we talking about? I doubt that a  typical 
  application would show any discernable difference in  execution times.
 
  One could test this easy enough by running both through 50k loops,  but 
  even then I doubt that the times would be that much different  -- but I 
  may be wrong, been there before.
 
  Cheers,
 
  tedd
 
  I don't know if there would be any difference either, which is why it  was 
  a question.
 
  Although Larry's suggestion of making the array static is something I 
  hadn't thought of.
 
  Overall it is an interesting concept to use an array instead of a  switch, 
  and I do wonder at what point, if any, that the two would  start to 
  diverge resource-wise.
 
  Would the array lookup be faster for a lesser-used option/key in a 
  situation where there were quite a few options? (you wouldn't have to  go 
  through the whole switch to get to the option at the end (?) or  would 
  you? I have no idea how that all works internally)
 
 Yes, you would.  It goes sequentially through each case:.  The array, on the 
 other hand, uses a hashing algorithm so it should be about even no matter 
 which option you pick.

Not quite. When the number of possible keys are small, a rote traversal
using language constructs such as if/elseif/else/case is likely to be
faster than incurring the overhead of the hash search. However, in
general the hash search will be faster. Having said that, the use of an
array to hold the key/value pairs produces a very succinct and readable
solution. Additionally, retrieval of such values from the database is
more easily implemented using the array methodology. For those not aware
of using static hash lookups with database results I've included an
example:

?php

function convert_from_weekday( $weekday )
{
static $days = null;

if( $days === null )
{
$query =
 SELECT 
weekday_id 
weekday_name 
FROM 
weekday_table ;

$days = array();
if( $db-query( $query ) )
{
while( $db-nextRow() )
{
$days[$db-getField( 'weekday_id' )] =
$days[$db-getField( 'weekday_name' )];
}
}
}

if( isset( $days[$weekday] ) )
{
return $days[$weekday];
}

return null;
}

?

Cheers,
Rob.
-- 
..
| InterJinn Application Framework - http://www.interjinn.com |
::
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for   |
| creating re-usable components quickly and easily.  |
`'

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



[PHP] Using array_search I get error

2007-03-11 Thread Richard Kurth
This array comes from  $_REQUEST of all data submitted
 
$array='Array ( [id] = 17 [takeaction] = saveCustomFields [notes] = --
Feb 4, 2007 @ 9:16 PM --fdsfdsfsdfdsfsfsfds -- Feb 4, 2007 @ 9:21 PM
--fdfdsfsdffsd -- February 11, 2007, @ 9:31 PM -- This is a tes -- February
14, 2007, @ 10:10 PM -- jhafjhfa afjahfajfhda kasjdaksdhADSKJL [firstname]
= NANCY [lastname] = ADKINS  [phone2] = [address1] = 25 ALWARD CT.
[address2] = [city] = MARTINSVILLE [State] = AK [other] = [zip] = 24112
[country] = US [date18] = 03-13-2007 [text19] = test1 [text20] =
[rating] = 0 [status] = Active )';
 when I use array_search to find date18

$key = array_search('date18', $array);  // $key = 1;
 
I get Wrong datatype for second argument 
How come the array is wrong datatype isn't a array an array or am I using
this wrong


Re: [PHP] Using array_search I get error

2007-03-11 Thread Stut

Richard Kurth wrote:

This array comes from  $_REQUEST of all data submitted
 
$array='Array ( [id] = 17 [takeaction] = saveCustomFields [notes] = --

Feb 4, 2007 @ 9:16 PM --fdsfdsfsdfdsfsfsfds -- Feb 4, 2007 @ 9:21 PM
--fdfdsfsdffsd -- February 11, 2007, @ 9:31 PM -- This is a tes -- February
14, 2007, @ 10:10 PM -- jhafjhfa afjahfajfhda kasjdaksdhADSKJL [firstname]
= NANCY [lastname] = ADKINS  [phone2] = [address1] = 25 ALWARD CT.
[address2] = [city] = MARTINSVILLE [State] = AK [other] = [zip] = 24112
[country] = US [date18] = 03-13-2007 [text19] = test1 [text20] =
[rating] = 0 [status] = Active )';
 when I use array_search to find date18

$key = array_search('date18', $array);  // $key = 1;
 
I get Wrong datatype for second argument 
How come the array is wrong datatype isn't a array an array or am I using

this wrong


$array is a string, and array_search is expecting an array, so it's 
correct. Where did you get that array?


-Stut

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



RE: [PHP] Using array_search I get error

2007-03-11 Thread Richard Kurth
 

-Original Message-
From: Stut [mailto:[EMAIL PROTECTED] 
Sent: Sunday, March 11, 2007 2:53 PM
To: Richard Kurth
Cc: php-general@lists.php.net
Subject: Re: [PHP] Using array_search I get error

Richard Kurth wrote:
 This array comes from  $_REQUEST of all data submitted
  
 $array='Array ( [id] = 17 [takeaction] = saveCustomFields [notes] = 
 -- Feb 4, 2007 @ 9:16 PM --fdsfdsfsdfdsfsfsfds -- Feb 4, 2007 @ 9:21 
 PM --fdfdsfsdffsd -- February 11, 2007, @ 9:31 PM -- This is a tes -- 
 February 14, 2007, @ 10:10 PM -- jhafjhfa afjahfajfhda 
 kasjdaksdhADSKJL [firstname] = NANCY [lastname] = ADKINS  [phone2] =
[address1] = 25 ALWARD CT.
 [address2] = [city] = MARTINSVILLE [State] = AK [other] = [zip] = 
 24112 [country] = US [date18] = 03-13-2007 [text19] = test1 
 [text20] = [rating] = 0 [status] = Active )';  when I use 
 array_search to find date18
 
 $key = array_search('date18', $array);  // $key = 1;
  
 I get Wrong datatype for second argument How come the array is wrong 
 datatype isn't a array an array or am I using this wrong

$array is a string, and array_search is expecting an array, so it's correct.
Where did you get that array?

-Stut

This array comes from  $_REQUEST of all data submitted from a form

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



Re: [PHP] PEAR not found

2007-03-11 Thread Chris

rwhartung wrote:

Hi all,
 I have a new install and am trying to get PEAR working - MDB2 to be exact.

I have modified /etc/php.ini to have the following

 include_path = .:/php/includes:/usr/share/pear

phpinfo() reports the directive --includedir=/usr/include

I can confirm that MDB2.php exists in that directory.
httpd has been restarted. I have literally copied the examples form the 
PEAR docs and I am using a postgresql backend using the bpsimple 
database that I can access with no problems with pg_connect() from a php 
script.


When using PEAR::MDB2 all I get is MDB2 Error:not found.


Ask on the pear list - http://pear.php.net/support/lists.php

and post the exact error message you're getting.. they will be able to 
help a lot more because they know the code base, we don't.


--
Postgresql  php tutorials
http://www.designmagick.com/

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



Re: [PHP] Using array_search I get error

2007-03-11 Thread Stut

Richard Kurth wrote:
 


-Original Message-
From: Stut [mailto:[EMAIL PROTECTED] 
Sent: Sunday, March 11, 2007 2:53 PM

To: Richard Kurth
Cc: php-general@lists.php.net
Subject: Re: [PHP] Using array_search I get error

Richard Kurth wrote:

This array comes from  $_REQUEST of all data submitted
 
$array='Array ( [id] = 17 [takeaction] = saveCustomFields [notes] = 
-- Feb 4, 2007 @ 9:16 PM --fdsfdsfsdfdsfsfsfds -- Feb 4, 2007 @ 9:21 
PM --fdfdsfsdffsd -- February 11, 2007, @ 9:31 PM -- This is a tes -- 
February 14, 2007, @ 10:10 PM -- jhafjhfa afjahfajfhda 
kasjdaksdhADSKJL [firstname] = NANCY [lastname] = ADKINS  [phone2] =

[address1] = 25 ALWARD CT.
[address2] = [city] = MARTINSVILLE [State] = AK [other] = [zip] = 
24112 [country] = US [date18] = 03-13-2007 [text19] = test1 
[text20] = [rating] = 0 [status] = Active )';  when I use 
array_search to find date18


$key = array_search('date18', $array);  // $key = 1;
 
I get Wrong datatype for second argument How come the array is wrong 
datatype isn't a array an array or am I using this wrong


$array is a string, and array_search is expecting an array, so it's correct.
Where did you get that array?

-Stut

This array comes from  $_REQUEST of all data submitted from a form


Yeah, you said that in your first post. What I meant was where did it 
come from?


What you have there is the output from print_r($_REQUEST). How exactly 
are you getting that string? Why are you creating it as a literal array 
rather than using $_REQUEST directly?


-Stut

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



[PHP] PHP 5.2 + IE 7 = HTTP 304 in login procedure

2007-03-11 Thread Yannick Warnier
Hello,

One of my clients is currently having a problem when logging into one of
my site.
Investigating further (because it works with Firefox with his login/pass
from my machine), it appears the problem is caused for an obscure reason
when IE7 requests the page and obviously does a conditional GET, which
only loads what's necessary for this login to proceed when the page has
been updated since last time. The returned HTTP header is 304: Not
modified, which is not returned with other browsers (others get a 200
header).
This is true for PHP pages as well as included CSS files, which triggers
the question of having any link to PHP at all...

I've looked on Google quite a bit, and if I have found people having the
same kind of problems, they generally report it along with the fact that
they use incorrectly the header('HTTP/1.1 ...'); or
header('Status: ...'); function, so the fix is generally a change of
these.

However, my application doesn't set any of these headers from inside the
PHP code.

Before I start getting into the whole Apache2 config (which I'm not to
good at) and try a lot of funny things in a bid to discover one element
that would cause this, I'd like to know...

Does anybody know the problem and have already found a fix?

Thanks,

Yannick

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



RE: [PHP] Using array_search I get error

2007-03-11 Thread Richard Kurth


Richard Kurth wrote:
  
 
 -Original Message-
 From: Stut [mailto:[EMAIL PROTECTED]
 Sent: Sunday, March 11, 2007 2:53 PM
 To: Richard Kurth
 Cc: php-general@lists.php.net
 Subject: Re: [PHP] Using array_search I get error
 
 Richard Kurth wrote:
 This array comes from  $_REQUEST of all data submitted
  
 $array='Array ( [id] = 17 [takeaction] = saveCustomFields [notes] 
 =
 -- Feb 4, 2007 @ 9:16 PM --fdsfdsfsdfdsfsfsfds -- Feb 4, 2007 @ 9:21 
 PM --fdfdsfsdffsd -- February 11, 2007, @ 9:31 PM -- This is a tes -- 
 February 14, 2007, @ 10:10 PM -- jhafjhfa afjahfajfhda 
 kasjdaksdhADSKJL [firstname] = NANCY [lastname] = ADKINS  [phone2] 
 =
 [address1] = 25 ALWARD CT.
 [address2] = [city] = MARTINSVILLE [State] = AK [other] = [zip] 
 =
 24112 [country] = US [date18] = 03-13-2007 [text19] = test1 
 [text20] = [rating] = 0 [status] = Active )';  when I use 
 array_search to find date18

 $key = array_search('date18', $array);  // $key = 1;
  
 I get Wrong datatype for second argument How come the array is wrong 
 datatype isn't a array an array or am I using this wrong
 
 $array is a string, and array_search is expecting an array, so it's
correct.
 Where did you get that array?
 
 -Stut
 
 This array comes from  $_REQUEST of all data submitted from a form

Yeah, you said that in your first post. What I meant was where did it come
from?

What you have there is the output from print_r($_REQUEST). How exactly are
you getting that string? Why are you creating it as a literal array rather
than using $_REQUEST directly?

What you have there is the output from print_r($_REQUEST). How exactly are
you getting that string? Why are you creating it as a literal array rather
than using $_REQUEST directly?

-Stut

This is for saving data from custom fields created by the user I don't know
what they are named so I can't use $_REQUEST[name] to pull them from the
array.
I am submitting a form to a script that will search thru the array and find
the fields that are in there date18 text19 text20 these are user custom
fields that I do not know what they are named. I what to compare what is in
the array  with a database table and if they match then save the information
in the array for that item to the database.

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



[PHP] php 4 and 5

2007-03-11 Thread edwardspl

Dear All,

What different between 4 and 5 ?

Edward.

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



Re: [PHP] php 4 and 5

2007-03-11 Thread Chris

[EMAIL PROTECTED] wrote:

Dear All,

What different between 4 and 5 ?


http://www.php.net/manual/en/migration5.php#migration5.changes

--
Postgresql  php tutorials
http://www.designmagick.com/

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



Re: [PHP] php 4 and 5

2007-03-11 Thread Larry Garfield
On Sunday 11 March 2007 7:14 pm, [EMAIL PROTECTED] wrote:
 Dear All,

 What different between 4 and 5 ?

 Edward.

http://us2.php.net/manual/en/faq.migration5.php
http://us2.php.net/manual/en/migration5.php

Really, I normally am not an RTFMer, but it's not like the information isn't 
already presented to you on a silver platter.

-- 
Larry Garfield  AIM: LOLG42
[EMAIL PROTECTED]   ICQ: 6817012

If nature has made any one thing less susceptible than all others of 
exclusive property, it is the action of the thinking power called an idea, 
which an individual may exclusively possess as long as he keeps it to 
himself; but the moment it is divulged, it forces itself into the possession 
of every one, and the receiver cannot dispossess himself of it.  -- Thomas 
Jefferson

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



Re: [PHP] php 4 and 5

2007-03-11 Thread Robert Cummings
On Mon, 2007-03-12 at 08:14 +0800, [EMAIL PROTECTED] wrote:
 Dear All,
 
 What different between 4 and 5 ?

http://www.php.net/manual/en/migration5.php#migration5.changes

Cheers,
Rob.
-- 
..
| InterJinn Application Framework - http://www.interjinn.com |
::
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for   |
| creating re-usable components quickly and easily.  |
`'

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



[PHP] xml parsing

2007-03-11 Thread Marije van Deventer
I have been trying to parse this xml, and want to use it with childnodes 
Label and Tekst, but sofar due to the li and p and image elements no 
luck. How can i do this in a simple way ???

?xml version=1.0 encoding=UTF-8?
Menu
 Item
  LabelAlgemeen/Label
  Teksta/Tekst
 /Item
 Item
  Label1-Atmosfeer/Label
  Tekst
  lia/li
  libbb/li
  liccc/li
  lidd/li
  img src=Saf2.jpg alt=News width=240 height=232/br /br /br 
/qqqbr /br /br //Tekst
 /Item
 Item
  LabelBetrouwbare drukcabine/Label
  Tekstimg src=Saf3.jpg alt=News 
width=180 height=239/br /br /br /br /br /br /br /br 
/br /br /br /br /br /br 
//Tekst
 /Item
/Menu

Re: [PHP] xml parsing

2007-03-11 Thread Robert Cummings
On Mon, 2007-03-12 at 01:38 +0100, Marije van Deventer wrote:
 I have been trying to parse this xml, and want to use it with
 childnodes Label and Tekst, but sofar due to the li and
 p and image elements no luck. How can i do this in a simple
 way ???

You're having trouble because the person who set the content of Tekst
didn't have a clue and so didn't mark up special entities. As such, the
XML has now taken on a mixed structure of XML and HTML.

You might have success performing the following before trying to parse:

?php

$xml = str_replace( 'Tekst', 'Tekst![CDATA[', $xml );
$xml = str_replace( '/Tekst', ']]/Tekst', $xml );

?

Cheers,
Rob.
-- 
..
| InterJinn Application Framework - http://www.interjinn.com |
::
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for   |
| creating re-usable components quickly and easily.  |
`'

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



Re: [PHP] Why won't this query go through?

2007-03-11 Thread Jochem Maas
Tijnema ! wrote:
 On 3/11/07, Mike Shanley [EMAIL PROTECTED] wrote:

 Hi,

 I am just not understanding what I could have possibly done wrong with
 this query. All of the variables are good, without special characters in
 any sense of the word... So why isn't it importing anything?

 Thanks!

 $q = INSERT INTO

 `visitors`(`username`,`password`,`email`,`firstname`,`lastname`,`birthdate`,`verifythis`)

VALUES ('.$username.',
'.md5($password1).',
'.$email.',
'.$firstname.',
'.$lastname.',
'.$birthdate.',
'.$verifythis.');;

^ -- oh my look at that, 
that's no good.

 mysql_query($q);
 
 
 * me is gettings crazy!!! 

you haven't been here very long have you Tijnema.

 ALWAYS USE THE MYSQL_ERROR COMMAND!

indeed.

 mysql_query($q);
 becomes
 mysql_query($q) or die(mysql_error());

only my stance is that the above construction sucks, it makes for very brittle
code and there is nothing to say whether when this query fails the whole script
needs to die ... another thing is that when the sql breaks your giving the
[potential] evil haxor b'std all the information he needs to perform some kind 
of
sql injection attack.

I recommend logging the error, and/or using some kind of debug mode in addition 
to
a more sophistication approach to deciding if/when to exit the script.

but the basic advice sticks: check your return values and examine any/all 
relevant
error messages.

 then post the result of the error, or fix it by yourself when you know
 where
 the error is.
 
 Tijnema
 
 -- 
 Mike Shanley

 ~you are almost there~

me? I've been there, smoked it and got the t-shirt to prove it.

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



Re: [PHP] Why won't this query go through?

2007-03-11 Thread Myron Turner

Jochem Maas wrote:

Tijnema ! wrote:
  

On 3/11/07, Mike Shanley [EMAIL PROTECTED] wrote:


Hi,

I am just not understanding what I could have possibly done wrong with
this query. All of the variables are good, without special characters in
any sense of the word... So why isn't it importing anything?

Thanks!

$q = INSERT INTO

`visitors`(`username`,`password`,`email`,`firstname`,`lastname`,`birthdate`,`verifythis`)

   VALUES ('.$username.',
   '.md5($password1).',
   '.$email.',
   '.$firstname.',
   '.$lastname.',
   '.$birthdate.',
   '.$verifythis.');;
  
Haven't you converted all of your columns to literals: 'username', etc, 
which should be plain username?


I find it's clearer to use the heredoc syntax:

$query= QUERY
INSERT INTO visitors (username,password,email,firstname,lastname. . . etc)
VALUES($username,$password,$email . . . etc )
QUERY;



_
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/

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



Re: [PHP] My help with adding captcha

2007-03-11 Thread Chris

Joker7 wrote:
Hi- as you know I have been working on adding a captcha image to my 
guestbook.
Well I have managed to get a very basic one working ;) but !I have been 
trying to get one that would make it more easy to use ,I have it working 
until I add it to my form.


My form use's print see below and I need to add this to it:


img style=vertical-align: middle src=?php echo 
captchaImgUrl()?nbsp;nbsp;input name=captcha size=8/

a href=?php echo captchaWavUrl()?Listen To This/a


And what happens when you try?

There's nothing in that snippet that shows an error (missing a 
semi-colon won't stop it printing as Tijnema suggested).



--
Postgresql  php tutorials
http://www.designmagick.com/

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



Re: [PHP] Variable variables and references

2007-03-11 Thread Martin Alterisio

2007/3/10, Dave Goodchild [EMAIL PROTECTED]:


Hi guys, I have just read 'Programming PHP' (O'Reilly) and although I
think
it's a great book, I am confused about variable variables and references -
not the mechanics, just where you would use them.

The subject of variable variables is explained but no examples are given
as
to why and where you would utilise them.



There really aren't useful and you're well without knowing they even exist.
In my opinion they harm code readibility, so they shouldn't be used,
especially if what you're trying to do can be achieved in some other way.

There is a special case where I found them useful. If you play competitions
like the sort of codegolf, they can be used to reduce your code by a few
characters by doing some really nasty things.

As for references, the examples given with regard to passing and returning

by reference in functions is clear, but no real examples are given as to
when this would be a preferred approcah - in fact, the authors stress that
due to PHP's copy-on-write mechanism, it is not a frequently-used
approcah.



References are useful to simulate PHP5 objects behaviour in PHP4. They can
be useful in many ways but I've found myself having too many troubles when
overusing them, segfaults and the sort...

So my question - are there any 'classic' situations in which either should

be used, and where and when do you guys use them in your real-world
efforts?
--
http://www.web-buddha.co.uk



[PHP] __autoload() no workie on my 5.2 install...

2007-03-11 Thread Nathan Hawks
Hey all.  This is my first post, 'coz it's the first time I've ever had
such a confusing problem with PHP.

I recently got a VPS and compiled PHP 5.2.1 with the following options:

--prefix=/usr/local/php5 --with-apxs2=/usr/local/apache2/bin/apxs
--with-config-file-path=/etc/php5 --with-curl
--with-curl-dir=/usr/local/lib --with-gd --with-gd-dir=/usr/local
--with-gettext --with-jpeg-dir=/usr/local/lib --with-kerberos
--with-mcrypt --with-mhash --with-mysql=/usr --with-pear
--with-png-dir=/usr/local/lib --with-xml --with-zlib
--with-zlib-dir=/usr/local/lib --with-zip --with-openssl --enable-bcmath
--enable-calendar --enable-ftp --enable-magic-quotes --enable-sockets
--enable-track-vars --enable-mbstring --enable-memory-limit
--with-freetype-dir=/usr/include/freetype2 --enable-soap
--with-mysql-sock=/tmp/mysql.sock

Apache is 2.2.4 and was also hand-compiled.

Meanwhile, at home, I have PHP 5.1.6 and Apache 2.2.3.

At home, __autoload() works great.

On the VPS, it doesn't work at all.

Here is a small case:
 = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - =
test.php:
?php
function __autoload($classname) {
  include_once(dirname(__FILE__) . /$classname.php);
}
$thinger = new foo();
echo $thinger-boo;
?
 = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - =
foo.php:
?php
class foo {
var $boo;
  function foo() {
$this-boo = I wouldn't say 'boo' if this autoloader worked on my
server...\n;
  }
}
?
 = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - =
And, the crying begins:
[EMAIL PROTECTED] ~]$ php test.php

Fatal error: Cannot instantiate non-existent class:  foo
in /home/nhawks/test.php on line 5

Naturally for this simple test case, both files are in the same
directory.  

When I do the same thing at home...
[EMAIL PROTECTED] ~]$ php test.php
I wouldn't say 'boo' if this autoloader worked on my server...

I don't understand why __autoload() would fail, I didn't explicitly
enable it when compiling at home and I can't find anything via Google to
help ... 

No clues whatsoever in my Apache error_log.  When I try throwing:
echo(Got here!\n);
..into my __autoload() function, it reveals that __autoload() is never
being fired.

Please help.

Nathan

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