php-general Digest 6 Apr 2011 12:49:33 -0000 Issue 7260

2011-04-06 Thread php-general-digest-help

php-general Digest 6 Apr 2011 12:49:33 - Issue 7260

Topics (messages 312273 through 312278):

Re: randomly random
312273 by: Richard Quadling
312274 by: Jim Lucas
312275 by: Stuart Dallas

Ranges for case statement and a WTF moment.
312276 by: Richard Quadling
312277 by: Richard Quadling

Newbi Question with calculate
312278 by: Silvio Siefke

Administrivia:

To subscribe to the digest, e-mail:
php-general-digest-subscr...@lists.php.net

To unsubscribe from the digest, e-mail:
php-general-digest-unsubscr...@lists.php.net

To post to the list, e-mail:
php-gene...@lists.php.net


--
---BeginMessage---
On 5 April 2011 15:07, Kirk Bailey kbai...@howlermonkey.net wrote:
 OK gang, to spew a single line from a file of fortune cookies, I want to
 read it and echo one line. While I found a 4 line code which gets it done, I
 thought there was a preexisting command to do exactly that. Any feedback on
 this?

motd

maybe.


-- 
Richard Quadling
Twitter : EE : Zend
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY
---End Message---
---BeginMessage---
On 4/5/2011 7:07 AM, Kirk Bailey wrote:
 OK gang, to spew a single line from a file of fortune cookies, I want to read 
 it
 and echo one line. While I found a 4 line code which gets it done, I thought
 there was a preexisting command to do exactly that. Any feedback on this?
 

No, but it can be done in one line:

?php

echo array_rand(@file(@$filename), 1);


# if you wanted to do a couple checks, you could do the following

if ( is_file(@$filename)  filesize($filename)  0 )
echo array_rand(file($filename), 1);

?

Jim Lucas
---End Message---
---BeginMessage---
On Tuesday, 5 April 2011 at 16:14, Jim Lucas wrote:
On 4/5/2011 7:07 AM, Kirk Bailey wrote:
  OK gang, to spew a single line from a file of fortune cookies, I want to 
  read it
  and echo one line. While I found a 4 line code which gets it done, I thought
  there was a preexisting command to do exactly that. Any feedback on this?
 
 No, but it can be done in one line:
 
 ?php
 
 echo array_rand(@file(@$filename), 1);
 
 
 # if you wanted to do a couple checks, you could do the following
 
 if ( is_file(@$filename)  filesize($filename)  0 )
  echo array_rand(file($filename), 1);
 
 ?

This method will eat memory unless you have a very small file.

Personally I would use filesize to get the length of the file, fopen it, fseek 
to a random position, then track back to a newline and use fgets to get the 
line. Then fclose, obviously.

Simples.

-Stuart

-- 
Stuart Dallas
3ft9 Ltd
http://3ft9.com/



---End Message---
---BeginMessage---
Hi.

I just wanted to quickly see if PHP supported ranges in its
switch/case statement (http://en.wikipedia.org/wiki/Ellipsis)

?php
$s = intval(date('s'));
switch($s)
{
case 0...9   : echo 'Between 0 and 9'; break;
case 10...19 : echo 'Between 10 and 19'; break;
case 20...29 : echo 'Between 20 and 29'; break;
case 30...39 : echo 'Between 30 and 39'; break;
case 40...49 : echo 'Between 40 and 49'; break;
case 50...59 : echo 'Between 50 and 59'; break;
default  : echo 'Unknown : ', $s;
}
?

Completely unexpectedly, the above code runs but produces the wrong output.

Interestingly, altering the number of dots and adding spaces all
result in parse errors ...

case 0..9 : // 2 dots, no spaces
case 0 .. 9 : // 2 dots, with spaces
case 0 ... 9 : // 3 dots, with spaces

It was confusing that the initial code ran without a parse error, but
considering that it did, it would suggest that the case values are
actually meaningful in some way.

php -r var_dump(10...19);

Interesting output ...

string(6) 100.19

And that took me a little while to work out.

It's all to do with PHP's type juggling.

10...19

What I'm not sure is why the middle empty string is output as 0.

10 . . .19 becomes 10 . 0 . .19 which becomes 100.19

Oddly, more . don't work.

php -r var_dump(1019);

all result in parse errors.

I don't know if this is a bug per se, but it is an oddity that I
though I'd share.

And what is even more surprising is that the initial code works in the
PHP V4.0.0. So maybe an 11 years old bug.

You really would have thought I'd have more to do with my time!

Regards,

Richard.



-- 
Richard Quadling
Twitter : EE : Zend
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY
---End Message---
---BeginMessage---
On 5 April 2011 16:28, Richard Quadling rquadl...@gmail.com wrote:
 Hi.

 I just wanted to quickly see if PHP supported ranges in its
 switch/case statement (http://en.wikipedia.org/wiki/Ellipsis)

 ?php
 $s = intval(date('s'));
 switch($s)
        {
        case 0...9   : echo 'Between 0 and 9'; break;
        case 10...19 : echo 'Between 10 and 19'; break;
        case 20...29 : echo 'Between 20 and 29'; break;
        case 30...39 : echo 'Between 30 and 39'; 

[PHP] Newbi Question with calculate

2011-04-06 Thread Silvio Siefke
Hello,


i have write a script for my Stock portfolio and now im not really find
something which can me help.

In the table php calculate me the Present Value and the Percent with
this code:


?php
//Quantity
$ABEI = 240;

//Buy Quote
$KKBEI = 41.31;

//Buy Balance
$KWBEI = 9914.40;

//calculate
include(../inc/quote.php); // Yahoo Quotes
$BEIERG = $KKBEI*$ABEI; // Buy Balance
$BEIDW = $BEIQuote['last']*$ABEI; // Present Value
$BEIAEN1 = $BEIQuote['last']-$KKBEI; // Quote Win
$BEIAEN = $BEIAEN1*100/$KKBEI; //Percent Win
?


Is it possible to apply logic to the whole table? Or do I write for each
additional item the same source code?


It were nice someone has a Tip for me? Thank u.


Silvio

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



[PHP] Re: Newbi Question with calculate

2011-04-06 Thread Jim Giner
I think you want to use the FOR loop to process each record in your table. 
You query (?) the table and then process each row in the result using the 
FOR and all your calculations on each one.  Look up FOR.
Silvio Siefke li...@silvio-siefke.de wrote in message 
news:4d9c6165.5040...@silvio-siefke.de...
 Hello,


 i have write a script for my Stock portfolio and now im not really find
 something which can me help.

 In the table php calculate me the Present Value and the Percent with
 this code:

 
 ?php
 //Quantity
 $ABEI = 240;

 //Buy Quote
 $KKBEI = 41.31;

 //Buy Balance
 $KWBEI = 9914.40;

 //calculate
 include(../inc/quote.php); // Yahoo Quotes
 $BEIERG = $KKBEI*$ABEI; // Buy Balance
 $BEIDW = $BEIQuote['last']*$ABEI; // Present Value
 $BEIAEN1 = $BEIQuote['last']-$KKBEI; // Quote Win
 $BEIAEN = $BEIAEN1*100/$KKBEI; //Percent Win
 ?


 Is it possible to apply logic to the whole table? Or do I write for each
 additional item the same source code?


 It were nice someone has a Tip for me? Thank u.


 Silvio 



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



Re: [PHP] Newbi Question with calculate

2011-04-06 Thread Me

I will give you a mysql example.

Apply the logic to the table during the query so you can just loop over the  
results like such.


$ABEI=12;
$query = ' select last * '.$ABEI.' AS resulta From table';






Sent via DROID on Verizon Wireless

-Original message-
From: Silvio Siefke li...@silvio-siefke.de
To: php-general@lists.php.net
Sent: Wed, Apr 6, 2011 12:50:20 GMT+00:00
Subject: [PHP] Newbi Question with calculate

Hello,


i have write a script for my Stock portfolio and now im not really find
something which can me help.

In the table php calculate me the Present Value and the Percent with
this code:


?php
//Quantity
$ABEI = 240;

//Buy Quote
$KKBEI = 41.31;

//Buy Balance
$KWBEI = 9914.40;

//calculate
include(../inc/quote.php); // Yahoo Quotes
$BEIERG = $KKBEI*$ABEI; // Buy Balance
$BEIDW = $BEIQuote['last']*$ABEI; // Present Value
$BEIAEN1 = $BEIQuote['last']-$KKBEI; // Quote Win
$BEIAEN = $BEIAEN1*100/$KKBEI; //Percent Win
?




Is it possible to apply logic to the whole table? Or do I write for each
additional item the same source code?


It were nice someone has a Tip for me? Thank u.


Silvio

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




Re: [PHP] Newbi Question with calculate

2011-04-06 Thread Silvio Siefke
Hello,

sorry i has not correct write.

The example when is finish can see at
http://silviosiefke.de/finance/stock/stock.php

For this i not use a mysql Database, its normal not so much at data.

I have write the source as Text Files:

http://silviosiefke.de/finance/finished/txt/index.txt
- That is the Start Page.

The included Files:
http://silviosiefke.de/finance/finished/txt/include.txt - Yahoo API
http://silviosiefke.de/finance/finished/txt/quote.txt - Yahoo Symbols
http://silviosiefke.de/finance/finished/txt/variable.txt - Calculate

If I calculate all the shares in my portfolio, then I have to create for
each share a file variable.php. Thats little long, is not the problem i
make it, but i think there is a chance to use the file variable.php at
moment for all what come in my portfolio?

For example at Moment i calculate Beiersdorf AG, the next in Portfolio
is Deutsche Bank AG. Now i must write a new variable.php for Deutsche
Bank. Or is there a chance that i can write one variable.php for all
Shares what i take in the portfolio.

Sorry for my english, i know its not perfect. Hope all can understand
what i mean. I learn every day and i find good that i not must use
google since few weeks.


Thanks for help, have nice day at all.


Regards
Silvio

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



[PHP] File Upload Problem

2011-04-06 Thread tedd

Hi gang:

I wrote a simple script to upload image files from my desktop to a 
server -- the exact same code works on two servers, but fails on a 
third.


I suspect there is something set different between the servers, but I 
can't find it.


Oddly enough, I can upload image files directly to the database, but 
not to the file system.


What could be wrong? What should I be looking for?

Cheers,

tedd

--
---
http://sperling.com/

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



Re: [PHP] File Upload Problem

2011-04-06 Thread Bastien Koert
On Wed, Apr 6, 2011 at 1:10 PM, tedd t...@sperling.com wrote:
 Hi gang:

 I wrote a simple script to upload image files from my desktop to a server --
 the exact same code works on two servers, but fails on a third.

 I suspect there is something set different between the servers, but I can't
 find it.

 Oddly enough, I can upload image files directly to the database, but not to
 the file system.

 What could be wrong? What should I be looking for?

 Cheers,

 tedd

 --
 ---
 http://sperling.com/

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



check out the max post size

-- 

Bastien

Cat, the other other white meat

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



Re: [PHP] File Upload Problem

2011-04-06 Thread Daniel Brown
On Wed, Apr 6, 2011 at 13:10, tedd t...@sperling.com wrote:
 Hi gang:

 I wrote a simple script to upload image files from my desktop to a server --
 the exact same code works on two servers, but fails on a third.

 I suspect there is something set different between the servers, but I can't
 find it.

 Oddly enough, I can upload image files directly to the database, but not to
 the file system.

 What could be wrong? What should I be looking for?

Are file uploads enabled and is the size of the file less than the
upload size limitation?  Is the disk or partition to which the
temporary files are being uploaded out of space, whereas the database
- perhaps on a different physical disk or partition - still has
sufficient free space?  Are you sure the user as which the web server
(presumably Apache) runs has permission to write to the temporary and
target directory?  Is the account near or at its disk quota?

-- 
/Daniel P. Brown
Network Infrastructure Manager
http://www.php.net/

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



[PHP] openssl question

2011-04-06 Thread Kai Renz
Hi,

i try to create a self signed certificate using this code:

?php

if(!isset($_GET['password']))
{
echo Error Code: 1;
exit(1);
}


if($_GET['password'] == )
{
echo Error Code 2;
exit(1);
}   

$password = mysql_real_escape_string($_GET['password']);



$dn = array(
countryName = DE,
stateOrProvinceName = test,
localityName = test,
organizationName = test,
organizationalUnitName = test,
commonName = test,
emailAddress = t...@test.de
);


$privkey = openssl_pkey_new();


$csr = openssl_csr_new($dn, $privkey);


$sscert = openssl_csr_sign($csr, null, $privkey, 365);

openssl_csr_export($csr, $csrout) and var_dump($csrout);
openssl_x509_export($sscert, $certout) and var_dump($certout);
openssl_pkey_export($privkey, $pkeyout, $password) and var_dump($pkeyout);

while (($e = openssl_error_string()) !== false) {
echo $e . \n;
}

?


But all i get is this:
Warning: openssl_csr_sign() [function.openssl-csr-sign]: cannot get
CSR from parameter 1 in
C:\xampp\htdocs\test\admin\create_self_signed_crt_action.php on line
42
Warning: openssl_csr_export() expects parameter 1 to be resource,
boolean given in
C:\xampp\htdocs\test\admin\create_self_signed_crt_action.php on line
51
Warning: openssl_x509_export() [function.openssl-x509-export]: cannot
get cert from parameter 1 in
C:\xampp\htdocs\test\admin\create_self_signed_crt_action.php on line
52
Warning: openssl_pkey_export() [function.openssl-pkey-export]: cannot
get key from parameter 1 in
C:\xampp\htdocs\test\admin\create_self_signed_crt_action.php on line
53
error:02001003:system library:fopen:No such process error:2006D080:BIO
routines:BIO_new_file:no such file error:0E064002:configuration file
routines:CONF_load:system lib error:02001003:system library:fopen:No
such process error:2006D080:BIO routines:BIO_new_file:no such file
error:0E064002:configuration file routines:CONF_load:system lib
error:02001003:system library:fopen:No such process error:2006D080:BIO
routines:BIO_new_file:no such file error:0E064002:configuration file
routines:CONF_load:system lib error:02001003:system library:fopen:No
such process error:2006D080:BIO routines:BIO_new_file:no such file
error:0E064002:configuration file routines:CONF_load:system lib

I'm using a windows box with xampp installed.

regards.

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



[PHP] Re: Ranges for case statement and a WTF moment.

2011-04-06 Thread Shawn McKenzie
On 04/05/2011 10:28 AM, Richard Quadling wrote:
 Hi.
 
 I just wanted to quickly see if PHP supported ranges in its
 switch/case statement (http://en.wikipedia.org/wiki/Ellipsis)
 
 ?php
 $s = intval(date('s'));
 switch($s)
   {
   case 0...9   : echo 'Between 0 and 9'; break;
   case 10...19 : echo 'Between 10 and 19'; break;
   case 20...29 : echo 'Between 20 and 29'; break;
   case 30...39 : echo 'Between 30 and 39'; break;
   case 40...49 : echo 'Between 40 and 49'; break;
   case 50...59 : echo 'Between 50 and 59'; break;
   default  : echo 'Unknown : ', $s;
   }
 ?
 
 Completely unexpectedly, the above code runs but produces the wrong output.

FYI. My first inclination would have been:

switch(true) {
   case in_array($s, range(0, 9)): echo 0 - 9; break;
}

But it's messy.

-- 
Thanks!
-Shawn
http://www.spidean.com

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



Re: [PHP] Ranges for case statement and a WTF moment.

2011-04-06 Thread David Harkness
On Tue, Apr 5, 2011 at 8:28 AM, Richard Quadling rquadl...@gmail.comwrote:

 php -r var_dump(10...19);

 Interesting output ...

 string(6) 100.19

 And that took me a little while to work out.

 It's all to do with PHP's type juggling.

 10...19

 What I'm not sure is why the middle empty string is output as 0.

 10 . . .19 becomes 10 . 0 . .19 which becomes 100.19


My guess is that PHP parses this as

10decimal-point dot-operator decimal-point19

Because the dot operator requires strings, PHP converts both numbers to
strings as

'10' dot-operator '0.19'

which becomes your

100.19

You can see this with

php  echo (string) 10.
10
php  echo (string) .19
0.19

David


[PHP] the best 1 book for php

2011-04-06 Thread Kirk Bailey

If I only had 1 book on php, what would it be?

--
end

Very Truly yours,
 - Kirk Bailey,
   Largo Florida

   kniht
  +-+
  | BOX |
  +-+
   think


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



Re: [PHP] the best 1 book for php

2011-04-06 Thread Michael Shadle
http://www.php.net/


On Wed, Apr 6, 2011 at 9:15 PM, Kirk Bailey kbai...@howlermonkey.net wrote:
 If I only had 1 book on php, what would it be?

 --
 end

 Very Truly yours,
                 - Kirk Bailey,
                   Largo Florida

                       kniht
                      +-+
                      | BOX |
                      +-+
                       think


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




Re: [PHP] the best 1 book for php

2011-04-06 Thread Jim Lucas

+1

1. Always current
2. Usable  evolving examples

On 4/6/2011 9:23 PM, Michael Shadle wrote:

http://www.php.net/


On Wed, Apr 6, 2011 at 9:15 PM, Kirk Baileykbai...@howlermonkey.net  wrote:

If I only had 1 book on php, what would it be?

--
end

Very Truly yours,
 - Kirk Bailey,
   Largo Florida

   kniht
  +-+
  | BOX |
  +-+
   think


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





--
Jim Lucas
www.cmsws.com

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



Re: [PHP] the best 1 book for php

2011-04-06 Thread Adam Richardson
On Thu, Apr 7, 2011 at 12:15 AM, Kirk Bailey kbai...@howlermonkey.netwrote:

 If I only had 1 book on php, what would it be?

 --
 end

 Very Truly yours,
 - Kirk Bailey,
   Largo Florida

   kniht
  +-+
  | BOX |
  +-+
   think


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


This is going to sound a little silly, but I'm going to say [drumroll...]

K  R (The C Programming Language)

Let me explain. I've recently reread (most of it anyway) K  R, and the
whole time I was reading I felt like I was studying up on PHP just as much
as C.

There's no language that played a bigger role in the design decisions, and
this is clearly evident when you listen to the core developers. In fact,
even this past week Rasmus said on the PHP Dev list, Argh! Everyone should
be forced to learn a bit of C. Like many PHP functions, the name and
argument order is right out of libc, a sentiment he's expressed before.

I must admit that I tend to think of PHP as C code that includes garbage
collection of lots of very practical web goodies. And, the book itself is a
gem in terms of clarity, brevity, and sage advice.

So, read (or read again for the umpteenth time) K  R, and then fill in the
gaps with PHP.net. And, on the rare occasion you would need more speed than
your PHP script is providing, you'll be able to write you're own extension
to PHP using it's older brother, C.

Adam

-- 
Nephtali:  A simple, flexible, fast, and security-focused PHP framework
http://nephtaliproject.com


[PHP] Re: File Upload Problem

2011-04-06 Thread Wojciech Kupiec

On 06/04/11 19:10, tedd wrote:

Hi gang:

I wrote a simple script to upload image files from my desktop to a
server -- the exact same code works on two servers, but fails on a third.

I suspect there is something set different between the servers, but I
can't find it.

Oddly enough, I can upload image files directly to the database, but not
to the file system.

What could be wrong? What should I be looking for?



The simplest explanation is that you don't have write permissions to the 
location where you upload the file or to the temp directory.


If you really want to get help, publish your code.


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