php-general Digest 7 Apr 2006 14:37:45 -0000 Issue 4058

Topics (messages 233412 through 233430):

Re: IF or SWITCH
        233412 by: Miles Thompson
        233414 by: Robert Cummings
        233423 by: Jad madi
        233427 by: Kevin Waterson

Re: int to string
        233413 by: sgsweb

Re: Faking Boolean
        233415 by: John Taylor-Johnston

Creating a Photo Album
        233416 by: Paul Goepfert
        233417 by: Barry
        233418 by: Chris
        233425 by: Gerry Danen
        233426 by: Jay Blanchard

Is it a bug of CakePHP?
        233419 by: Pham Huu Le Quoc Phuc
        233420 by: nicolas figaro
        233421 by: Pham Huu Le Quoc Phuc

Re: how to kill session id without closing the window?
        233422 by: rich gray

Problems with Arrays and print and echo
        233424 by: Michael Felt

getimagesize()
        233428 by: Ed Curtis
        233429 by: John Nichel

make global variables accessible to functions?
        233430 by: Bing Du

Administrivia:

To subscribe to the digest, e-mail:
        [EMAIL PROTECTED]

To unsubscribe from the digest, e-mail:
        [EMAIL PROTECTED]

To post to the list, e-mail:
        [email protected]


----------------------------------------------------------------------
--- Begin Message ---
At 11:40 PM 4/6/2006, Kevin Waterson wrote:

This one time, at band camp, Robert Cummings <[EMAIL PROTECTED]> wrote:

> I'm gonna go out on a limb here and say WRONG!
>
> Run yourself a benchmark.

benchmarks can be hazardous, but lets look at them at their most basic level. By this
I mean how folks use them every day...

http://www.phpro.org/benchmarks/if-switch-benchmark.html

Kind regards
Kevin
--


Actually, a minimal victory.
If it can be used, I'd go for the clarity of switch.

M.


--
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.1.385 / Virus Database: 268.3.5/302 - Release Date: 4/5/2006

--- End Message ---
--- Begin Message ---
On Thu, 2006-04-06 at 22:40, Kevin Waterson wrote:
> This one time, at band camp, Robert Cummings <[EMAIL PROTECTED]> wrote:
> 
> > I'm gonna go out on a limb here and say WRONG!
> > 
> > Run yourself a benchmark.
> 
> benchmarks can be hazardous, but lets look at them at their most basic level. 
> By this
> I mean how folks use them every day...
> 
> http://www.phpro.org/benchmarks/if-switch-benchmark.html

Hazardous is right. That's a terrible benchmark. Could have eliminated
hundreds of sources of skew by running the iterations at the command
line. It even does an echos *lol*.

I ran the following as two shell scripts, 10 times each and averaged the
times to get that switch is faster by 0.000000122 secs. Big whup, as I
said in a previous post, that's very likely due to the precomputation
being assigned in userland PHP versus the internal engine. As for which
one is best, that's just flamebait -- right up there with preferred
braces style, tabs or spaces to indent, top post versus bottom post
*teehee*, etc. Personally I prefer if/elseif/else for a moderate number
of conditions or if the conditional expressions are very complex. Switch
I generally use for a large set of constants. They both have readability
pros and cons.

Cheers,
Rob.

<?php

for( $i = 0; $i < 1000000; $i++ )
{
    $foo = 3;
    if( $foo == 1 )
    {
    }
    else
    if( $foo == 2 )
    {
    }
    else
    if( $foo == 3 )
    {
    }
    else
    if( $foo == 4 )
    {
    }
    else
    {
    }
}

?>

<?php

for( $i = 0; $i < 1000000; $i++ )
{
    $foo = 3;
    switch( $foo )
    {
        case 1:
        {
            break;
        }
        case 2:
        {
            break;
        }
        case 3:
        {
            break;
        }
        case 4:
        {
            break;
        }
        default:
        {
        }
    }
}

?>

*Wheeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee* ;)

-- 
.------------------------------------------------------------.
| 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.          |
`------------------------------------------------------------'

--- End Message ---
--- Begin Message ---
Kevin, 
I'm just curious to know how to did you do that benchmark.


On Fri, 2006-04-07 at 12:40 +1000, Kevin Waterson wrote:
> This one time, at band camp, Robert Cummings <[EMAIL PROTECTED]> wrote:
> 
> > I'm gonna go out on a limb here and say WRONG!
> > 
> > Run yourself a benchmark.
> 
> benchmarks can be hazardous, but lets look at them at their most basic level. 
> By this
> I mean how folks use them every day...
> 
> http://www.phpro.org/benchmarks/if-switch-benchmark.html
> 
> Kind regards
> Kevin
> -- 
> "Democracy is two wolves and a lamb voting on what to have for lunch. 
> Liberty is a well-armed lamb contesting the vote."
> 

--- End Message ---
--- Begin Message ---
This one time, at band camp, Jad madi <[EMAIL PROTECTED]> wrote:

> Kevin, 
> I'm just curious to know how to did you do that benchmark.

Sure, use ab (Apache Benchmark) which comes with your build of apache.
Simply create your file foo.php and give ab the command
ab http://www.example.com/foo.php -n 10000 -c 4

you may also use localhost as such
ab http://localhost/foo.php -n 10000 -c 4

If the concurrency is omitted a concurrency of 1 is assumed

This will tell ab the url, and to request it 10,000 times with a concurrency of 
4.
Depending on your hardware ab will tick over and generate a report.

man ab will give you more info

Kind regards
Kevin

-- 
"Democracy is two wolves and a lamb voting on what to have for lunch. 
Liberty is a well-armed lamb contesting the vote."

--- End Message ---
--- Begin Message ---
Hi Tanner,

Here's a completely working piece of code that I got from my hosting company. This looks like it does exactly what you want to do. I am also including the output in the bottom of this e-mail.

sunil.
<?
 /******************************************************************
 **
 ** Class: num2str
 ** Description: This class converts a number into its corresponding
 **    text represenation.
 **    e.g., input: 1,001 => output: one thousand one
 ** Written By: Websulting (www dot websulting dot com)
 ** Copyright: You are free to use this script as you like.  This
 **    script come with absolutely no guarantee.  You must leave
 **    this copyright notice with this file.
 **    Report bugs to: contact at websulting dot com
 **
 ******************************************************************/
 class num2str {
   var $one_a=array(
       "one","two","three","four","five","six","seven",
       "eight","nine","ten","eleven","twelve","thirteen",
       "fourteen","fifteen","sixteen","seventeen","eighteen","ninteen");
   var $ten_a=array(
       "ten","twenty","thirty","forty","fifty","sixty","seventy",
       "eighty","ninty");
   var $mil_a=array("thousand","million","billion","trillion");

   //*********************************************************
   //
   // Method: convert
   // Description: Convert the input number to string representation
   //
   //*********************************************************
   function convert ($num) {
     $triplets = preg_split('/,/',$num,-1,PREG_SPLIT_NO_EMPTY);
     $length = count($triplets);
     $plc_a= array();
     for ($i=0;$i<$length;$i++) {$plc_a[$i]=$this->tonum($triplets[$i]);}
     $rval = "";
     foreach ($plc_a as $k) {
       if ($k == "") {$length--;continue;}
       $rval .= "$k ". $this->getplace($length--). " ";
     }
     return $rval;
   }

   //*********************************************************
   //
   // Method: getplace
   // Description: Get the place of the digits.
   //
   //*********************************************************
   function getplace($i) {
     return $this->mil_a[$i-2];
   }

   //*********************************************************
   //
   // Method: tonum
   // Description: Convert the individual set to text
   //
   //*********************************************************
   function tonum ($num) {
     $len = strlen($num);
     switch ($len) {
       case 3:
         if (substr($num,1,2) <=19) {
           return $this->one_a[substr($num,0,1)-1].
             (substr($num,0,1)==0 ? "" : " hundred ").
             $this->one_a[substr($num,1,2)-1];
         }
         return $this->one_a[substr($num,0,1)-1] .
             (substr($num,0,1)==0 ? "" : " hundred ").
             $this->ten_a[substr($num,1,1)-1]." ".
             $this->one_a[substr($num,2,1)-1];
       case 2:
         if (substr($num,0,2) <=19) {
           return $this->one_a[substr($num,0,2)-1];
         }
         return $this->ten_a[substr($num,0,1)-1]." ".
         $this->one_a[substr($num,1,1)-1];
       case 1:
         return $this->one_a[substr($num,0,1)-1];
     }
   }
 }
 //End of class num2str

 $obj = new num2str();
foreach (array("1,121","121","1,000,010,000,321","1,109,019,000,321", "100","70","10","15","5") as $num) {
   print "[$num] => " . $obj->convert($num)."\n";
 }
?>

output:

[1,121] => one thousand one hundred twenty one
[121] => one hundred twenty one
[1,000,010,000,321] => one trillion ten million three hundred twenty one
[1,109,019,000,321] => one trillion one hundred nine billion ninteen million three hundred twenty one
[100] => one hundred
[70] => seventy
[10] => ten
[15] => fifteen
[5] => five

--- End Message ---
--- Begin Message ---
Thanks!
Your first appraoch seems to make clearer sense for me.
Great pinch hit,
John

Paul Novitski wrote:

If you're splitting your search string into discrete words, most search engine logic doesn't require quotes. Typically, quotation marks combine multiple words into single expressions, which makes sense with "John Johnston" but not with "John" "Johnston".

But since you requested the quotes I'll include them:

Here's one way to convert an incoming word series for a search:

        // get the entered text
        $sEnquiry = $_GET["searchenquiry"];

RESULT: [ john    johnston ]

        // protect against input attacks here
        ...

        // remove whitespace from beginning & end
        $sEnquiry = trim($sEnquiry);

RESULT: [john    johnston]

        // replace internal whitespace with single spaces
        $sEnquiry = preg_replace("/\s+/", " ", $sEnquiry);

RESULT: [john johnston]

        // replace each space with quote-space-plus-quote
        $sEnquiry = str_replace(" ", "\" +\"", $sEnquiry);

RESULT: [john" +"johnston]

        // add beginning & ending delimiters
        $sEnquiry = "+\"" . $sEnquiry . "\"";

RESULT: [+"john" +"johnston"]


--- End Message ---
--- Begin Message ---
Hi all,

I am postilng pictures up on a website.  So far I have a picture per
page. This will get not be very efficient as time goes on.  Is there
anyway that I can have one page with only the image updating?  Can
this be done in PHP.  If it can would someone explain it to me.  The
only thing I k.now how to do well in PHP is mysql queries and data
validatlion.

Thanks,
Paul

--- End Message ---
--- Begin Message ---
Paul Goepfert wrote:
Hi all,

I am postilng pictures up on a website.  So far I have a picture per
page. This will get not be very efficient as time goes on.  Is there
anyway that I can have one page with only the image updating?  Can
this be done in PHP.  If it can would someone explain it to me.  The
only thing I k.now how to do well in PHP is mysql queries and data
validatlion.

Thanks,
Paul
No PHP can't do something like that.
Problem is that PHP can't delete the output Buffer.

I think, but i am not quite sure, that this can be done with AJAX.
Also some Java-Applets are able to do stuff like that.

It will still be tough since you have to tell your browser somehow that he has to reload the image.
Not quite easy.

Greets
        Barry

--
Smileys rule (cX.x)C --o(^_^o)
Dance for me! ^(^_^)o (o^_^)o o(^_^)^ o(^_^o)

--- End Message ---
--- Begin Message ---
Paul Goepfert wrote:
Hi all,

I am postilng pictures up on a website.  So far I have a picture per
page. This will get not be very efficient as time goes on.  Is there
anyway that I can have one page with only the image updating?  Can
this be done in PHP.  If it can would someone explain it to me.  The
only thing I k.now how to do well in PHP is mysql queries and data
validatlion.

this might give you some ideas:
http://www.cssplay.co.uk/menu/lightbox.html

you could do it in flash too:
http://www.airtightinteractive.com/simpleviewer/

there is probably something already out there to do what you want ;)

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

--- End Message ---
--- Begin Message ---
Sure you can, Paul. See
http://www.lily-gallery.com/h/showlily.php?id=53&div=1 for an example.
There are 5 thumbnails and they all link to photo.php to display the
larger version.

On 4/7/06, Paul Goepfert <[EMAIL PROTECTED]> wrote:
> Hi all,
>
> I am postilng pictures up on a website.  So far I have a picture per
> page. This will get not be very efficient as time goes on.  Is there
> anyway that I can have one page with only the image updating?  Can
> this be done in PHP.  If it can would someone explain it to me.  The
> only thing I k.now how to do well in PHP is mysql queries and data
> validatlion.



--
Gerry
http://dev.danen.org/

--- End Message ---
--- Begin Message ---
[snip]
I am postilng pictures up on a website.  So far I have a picture per
page. This will get not be very efficient as time goes on.  Is there
anyway that I can have one page with only the image updating?  Can
this be done in PHP.  If it can would someone explain it to me.  The
only thing I k.now how to do well in PHP is mysql queries and data
validatlion.
[/snip]

Check out http://gallery.menalto.com/ There is a way to watch a
slideshow in a single page, but it uses a Java component. 
http://www.akehrer.com/ffgallery/ is an Ajax and PHP photo gallery (it
resembles Lightbox), but it doesn't have the action that you require.
http://www.frwrd.net/minishowcase/ is another Ajax attempt.

--- End Message ---
--- Begin Message ---
I catch an error, could you tell me if you have some ideas?

class Dsptraining extends AppModel
{
     function GetDsptrainings()
     {
          return $this->findBySql("select max(start_date) start_date from
tbl_dsptrainings");
     }
}

class DsptrainingsController extends AppController
{
        function index()
        {
          $data = $this->Dsptraining->GetDsptrainings();
          echo $data[0]['start_date'];
      }
}

Error message: Undefined index: start_date in
c:\Inetpub\wwwroot\Cake\app\controllers\dsptrainings_controller.php on line
33

--- End Message ---
--- Begin Message ---
Pham Huu Le Quoc Phuc a écrit :
I catch an error, could you tell me if you have some ideas?

class Dsptraining extends AppModel
{
     function GetDsptrainings()
     {
          return $this->findBySql("select max(start_date) start_date from
tbl_dsptrainings");
     }
}

did you try your sql query directly using sql ?
try this one :

select max(start_date) as start_date from tbl_dsptrainings

N F
class DsptrainingsController extends AppController
{
        function index()
        {
          $data = $this->Dsptraining->GetDsptrainings();
          echo $data[0]['start_date'];
      }
}

Error message: Undefined index: start_date in
c:\Inetpub\wwwroot\Cake\app\controllers\dsptrainings_controller.php on line
33


--- End Message ---
--- Begin Message ---
Thanks for relying!
But, Do not have anyway to solve this problem.

----- Original Message -----
From: "nicolas figaro" <[EMAIL PROTECTED]>
To: <[email protected]>
Sent: Friday, April 07, 2006 3:49 PM
Subject: Re: [PHP] Is it a bug of CakePHP?


> Pham Huu Le Quoc Phuc a écrit :
> > I catch an error, could you tell me if you have some ideas?
> >
> > class Dsptraining extends AppModel
> > {
> >      function GetDsptrainings()
> >      {
> >           return $this->findBySql("select max(start_date) start_date
from
> > tbl_dsptrainings");
> >      }
> > }
> >
> >
> did you try your sql query directly using sql ?
> try this one :
>
> select max(start_date) as start_date from tbl_dsptrainings
>
> N F
> > class DsptrainingsController extends AppController
> > {
> >         function index()
> >         {
> >           $data = $this->Dsptraining->GetDsptrainings();
> >           echo $data[0]['start_date'];
> >       }
> > }
> >
> > Error message: Undefined index: start_date in
> > c:\Inetpub\wwwroot\Cake\app\controllers\dsptrainings_controller.php on
line
> > 33
> >
> >
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>

--- End Message ---
--- Begin Message ---
[chop]
How can I create new, other sesssion id (after I, for example, click on
'Log Out' button) without closing window?

Thanks for any help.

er .. session_regenerate_id()

hth
rich

--- End Message ---
--- Begin Message ---
Slowly I am getting the output I want.

Trying to use "dynamic" arrays, does creat the array I want, but getting the info is sometimes surprising.

I notice a difference between arrays used locally in a function, and arrays used as a 'var' in a class function (all in PHP 4 atm).

Code snippet:
                echo "ROWS returned are: $max\n";
                $this->count = $max;

                while ($max--) {
                        $row = mysql_fetch_row($result);
                        $this->name[$max] = sprintf("%s", $row[0]);
                        $Name[$max] = sprintf("%s", $row[0]);
echo "init \$this->Xame[$max] = $row[0]";
echo " $Name[$max] $this->name[$max]\n";
                        $regionID[$max] = $row[1];
                        $constellationID[$max] = $row[2];
$this->ID[$max] = $row[3]; printf("%d:%d/%d/%s\n",$max,$regionID[$max],$constellationID[$max],
                               $this->name[$max]);
                }
================
Line wrap is messing things up a bit.
Was trying sprintf to see if the was a buffer problem coming from mysql.
Problem seems to be the same, regardless.
Also, the names changes ($this->name[] versus $Name[]) are deliberate, for just in case....
================

Output (debuging):
ROWS returned are: 7
init $this->Xame[6] = 8-TFDX 8-TFDX Array[6]
6:10000003/20000044/8-TFDX
init $this->Xame[5] = B-E3KQ B-E3KQ Array[5]
5:10000003/20000044/B-E3KQ
init $this->Xame[4] = BR-6XP BR-6XP Array[4]
4:10000003/20000044/BR-6XP
init $this->Xame[3] = G5ED-Y G5ED-Y Array[3]
3:10000003/20000044/G5ED-Y
init $this->Xame[2] = O-LR1H O-LR1H Array[2]
2:10000003/20000044/O-LR1H
init $this->Xame[1] = UL-4ZW UL-4ZW Array[1]
1:10000003/20000044/UL-4ZW
init $this->Xame[0] = Y5J-EU Y5J-EU Array[0]
0:10000003/20000044/Y5J-EU
++++++++++++++++++++++++++++++++++++++++++++++
Thanks for your ideas, help, etc..

Maybe it is somethign as simple as "can't do that with echo", but when the arrays are all single element ( foo_array[0] is only element ) all statements work as expected.

regards,
Michael

--- End Message ---
--- Begin Message ---
 Can you call getimagesize() multiple times in one script? I'm trying to
use it multiple times but it only seems to work in the first loop I call
it in. I read something in the docs about it cacheing the results and
didn't know if this has something to do with it.

 I also tried creating an array out of the results I get from it but it
will only output the size values when it's building the array, never when
I try to loop back through it and output the values.

Thanks,

Ed

--- End Message ---
--- Begin Message ---
Ed Curtis wrote:
 Can you call getimagesize() multiple times in one script? I'm trying to
use it multiple times but it only seems to work in the first loop I call
it in. I read something in the docs about it cacheing the results and
didn't know if this has something to do with it.

That 'something' you read was a user comment, not the manual. AFAIK, getimagesize() *does no* cache.

 I also tried creating an array out of the results I get from it but it
will only output the size values when it's building the array, never when
I try to loop back through it and output the values.


Without seeing any code, I can only guess that you're doing something wrong, and need to fix it.

--
John C. Nichel IV
Programmer/System Admin (ÜberGeek)
Dot Com Holdings of Buffalo
716.856.9675
[EMAIL PROTECTED]

--- End Message ---
--- Begin Message ---
Hello,

We use PHP 4.3.9. 'register_globals = Off' is set in php.ini.  I've heard
using 'global' could cause security problems.  Is using $GLOBALS still not
more secure than using the 'global' keyword? How should function foo()
obtain the value of $a?

====
<?php

$a = 'one';
foo();

function foo () {
global $a;
echo "a is $a";

}
?>
===

Thanks in advance,

Bing

--- End Message ---

Reply via email to