php-general Digest 16 Mar 2010 12:34:24 -0000 Issue 6642

Topics (messages 302880 through 302889):

Re: Need routine to tell me number of dimensions in array.
        302880 by: Ashley Sheridan
        302881 by: Jim Lucas
        302882 by: Robert Cummings

Re: PHP in HTML code
        302883 by: Ford, Mike
        302884 by: Ashley Sheridan
        302885 by: Ford, Mike
        302889 by: Bob McConnell

Spreadsheet_Excel_Reader problem
        302886 by: I am on the top of the world! Borlange University
        302888 by: Ashley Sheridan

Re: php-cli
        302887 by: Richard Quadling

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


----------------------------------------------------------------------
--- Begin Message ---
On Mon, 2010-03-15 at 17:23 -0700, Daevid Vincent wrote:

> Oh. I know it's not a simple solution to do right Ashley. And exacerbated
> by the fact that each array dimension can have different dimensions as
> well. This is why I wanted someone else's solution first before I spend
> hours or days on one that works reliably. :)
> 
> 
>   _____  
> 
> From: Ashley Sheridan [mailto:a...@ashleysheridan.co.uk] 
> Sent: Monday, March 15, 2010 4:44 PM
> Subject: Re: [PHP] Need routine to tell me number of dimensions in array
> 
> The only way to do it reliably would be to iterate the entire array,
> element by element, as all the elements of an array might not necessarily
> be all of the array type or int's.
> 
> 


Best way I can think of is to iterate the entire thing and keep a count
as you do. I'm not aware of any functions that can do what you need
there.

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



--- End Message ---
--- Begin Message ---
Daevid Vincent wrote:
> Anyone have a function that will return an integer of the number of
> dimensions an array has?
> 
> I did some quick searches and came up with nothing. 
> The closest was here of someone asking the same thing, but his solution
> isn't right:
> http://www.bigresource.com/PHP-count-array-dimensions-VrIahx1b.html
> http://php.net/manual/en/function.count.php
> 
> From a human standpoint, it's easy to see, "oh, this is a TWO
> dimensional"...
> 

How about this...  Using a slightly modified array that you posted, I came up
with this in about 10 minutes

<pre>I am working with the following data structure

<?php

$in = array(
  0 => array(
    0 => array('Flight Number', 'flight_number'),
    1 => array(
        0 => array('Timestamp Departure', 'timestamp_departure'),
        1 => array('Timestamp Arrival', 'timestamp_arrival'),
      )
    ),
  1 => array('Departure City', 'departure_city'),
  2 => array('Arrival City', 'arrival_city'),
);

print_r($in);

echo "\n\n";

$max_depth = 0;
$cur_depth = 0;
function max_array_depth($ar) {
        global $cur_depth, $max_depth;
        if ( is_array($ar) ) {
                $cur_depth++;
                if ( $cur_depth > $max_depth ) {
                        $max_depth = $cur_depth;
                }
                foreach ( $ar AS $row ) {
                        max_array_depth($row);
                }
                $cur_depth--;
        }
}

max_array_depth($in);

echo "Max depth of array is: {$max_depth}";

?></pre>

http://www.cmsws.com/examples/php/testscripts/dae...@daevid.com/0002.php

-- 
Jim Lucas
NOC Manager
541-323-9113
BendTel, Inc.
http://www.bendtel.com

--- End Message ---
--- Begin Message ---
Jim Lucas wrote:
Daevid Vincent wrote:
Anyone have a function that will return an integer of the number of
dimensions an array has?

I did some quick searches and came up with nothing. The closest was here of someone asking the same thing, but his solution
isn't right:
http://www.bigresource.com/PHP-count-array-dimensions-VrIahx1b.html
http://php.net/manual/en/function.count.php

From a human standpoint, it's easy to see, "oh, this is a TWO
dimensional"...


How about this...  Using a slightly modified array that you posted, I came up
with this in about 10 minutes

<pre>I am working with the following data structure

<?php

$in = array(
  0 => array(
    0 => array('Flight Number', 'flight_number'),
    1 => array(
        0 => array('Timestamp Departure', 'timestamp_departure'),
        1 => array('Timestamp Arrival', 'timestamp_arrival'),
      )
    ),
  1 => array('Departure City', 'departure_city'),
  2 => array('Arrival City', 'arrival_city'),
);

print_r($in);

echo "\n\n";

$max_depth = 0;
$cur_depth = 0;
function max_array_depth($ar) {
        global $cur_depth, $max_depth;
        if ( is_array($ar) ) {
                $cur_depth++;
                if ( $cur_depth > $max_depth ) {
                        $max_depth = $cur_depth;
                }
                foreach ( $ar AS $row ) {
                        max_array_depth($row);
                }
                $cur_depth--;
        }
}

max_array_depth($in);

echo "Max depth of array is: {$max_depth}";

?></pre>

http://www.cmsws.com/examples/php/testscripts/dae...@daevid.com/0002.php

Globals are dirty for this kind of recursive utility function. Here's a cleaner example:
<?php

function get_array_depth( $array )
{
    if( !is_array( $array ) )
    {
        return 0;
    }

    $maxDepth = 0;
    foreach( $array as $value )
    {
        if( ($subDepth = get_array_depth( $value )) > $maxDepth )
        {
            $maxDepth = $subDepth;
        }
    }

    return 1 + $maxDepth;
}

?>

Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP

--- End Message ---
--- Begin Message ---
> -----Original Message-----
> From: Bob McConnell [mailto:r...@cbord.com]
> Sent: 15 March 2010 18:13
> 
> From: Jochem Maas
> 
> > Op 3/13/10 3:49 PM, Jorge Gomes schreef:
> >> First of all, i recommend the use of normal php tags (<?php ...
> ?>)
> because
> >> the short tags are atm marked as* **DEPRECATED*.
> >
> > that's a documentation error.
> 
> No it's not. The short tags conflict with both XML and XHTML and
> therefore are being phased out.

Jochem is right, Bob and Jorge are wrong.

Proof: http://marc.info/?l=php-internals&m=126832992915664&w=2 

Cheers!

Mike
 -- 
Mike Ford,
Electronic Information Developer, Libraries and Learning Innovation,  
Leeds Metropolitan University, C507, Civic Quarter Campus, 
Woodhouse Lane, LEEDS,  LS1 3HE,  United Kingdom 
Email: m.f...@leedsmet.ac.uk 
Tel: +44 113 812 4730





To view the terms under which this email is distributed, please go to 
http://disclaimer.leedsmet.ac.uk/email.htm

--- End Message ---
--- Begin Message ---
On Tue, 2010-03-16 at 11:16 +0000, Ford, Mike wrote:

> > -----Original Message-----
> > From: Bob McConnell [mailto:r...@cbord.com]
> > Sent: 15 March 2010 18:13
> > 
> > From: Jochem Maas
> > 
> > > Op 3/13/10 3:49 PM, Jorge Gomes schreef:
> > >> First of all, i recommend the use of normal php tags (<?php ...
> > ?>)
> > because
> > >> the short tags are atm marked as* **DEPRECATED*.
> > >
> > > that's a documentation error.
> > 
> > No it's not. The short tags conflict with both XML and XHTML and
> > therefore are being phased out.
> 
> Jochem is right, Bob and Jorge are wrong.
> 
> Proof: http://marc.info/?l=php-internals&m=126832992915664&w=2 
> 
> Cheers!
> 
> Mike
>  -- 
> Mike Ford,
> Electronic Information Developer, Libraries and Learning Innovation,  
> Leeds Metropolitan University, C507, Civic Quarter Campus, 
> Woodhouse Lane, LEEDS,  LS1 3HE,  United Kingdom 
> Email: m.f...@leedsmet.ac.uk 
> Tel: +44 113 812 4730
> 
> 
> 
> 
> 
> To view the terms under which this email is distributed, please go to 
> http://disclaimer.leedsmet.ac.uk/email.htm
> 


That's not really proof of anything, it's just an archived email from
this list...

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



--- End Message ---
--- Begin Message ---
> -----Original Message-----
> From: Ashley Sheridan [mailto:a...@ashleysheridan.co.uk]
> Sent: 16 March 2010 11:16
> 
> On Tue, 2010-03-16 at 11:16 +0000, Ford, Mike wrote:
> 
> > 
> > Proof: http://marc.info/?l=php-internals&m=126832992915664&w=2
> > 
> 
> That's not really proof of anything, it's just an archived email
> from this list...

Well, firstly it's an archived email from the *internals* (i.e. PHP developers) 
list, not this one. And secondly it's from someone whom I trust to know what 
he's talking about. If I looked, I'm sure I could dig up several similarly 
definitive (but less recent) pronouncements from PHP "names", including Rasmus 
himself.

In fact: http://marc.info/?l=php-internals&m=123969574312781&w=2 

Cheers!

Mike

 -- 
Mike Ford,
Electronic Information Developer, Libraries and Learning Innovation,  
Leeds Metropolitan University, C507, Civic Quarter Campus, 
Woodhouse Lane, LEEDS,  LS1 3HE,  United Kingdom 
Email: m.f...@leedsmet.ac.uk 
Tel: +44 113 812 4730





To view the terms under which this email is distributed, please go to 
http://disclaimer.leedsmet.ac.uk/email.htm

--- End Message ---
--- Begin Message ---
From: Ford, Mike
> From: Ashley Sheridan
>> On Tue, 2010-03-16 at 11:16 +0000, Ford, Mike wrote:
>> 
> >> 
> >> Proof: http://marc.info/?l=php-internals&m=126832992915664&w=2
> >> 
>> 
>> That's not really proof of anything, it's just an archived email
>> from this list...
> 
> Well, firstly it's an archived email from the *internals* (i.e.
> PHP developers) list, not this one. And secondly it's from
> someone whom I trust to know what he's talking about. If I
> looked, I'm sure I could dig up several similarly definitive
> (but less recent) pronouncements from PHP "names", including
> Rasmus himself.
> 
> In fact: http://marc.info/?l=php-internals&m=123969574312781&w=2 

Well, that's their prerogative, but I believe they are wrong. Short tags
cause more problems than they will ever solve, and should be removed
from the language ASAP. I would classify that as a design flaw.

In the meantime, since we are upgrading our pages to XHTML, we are
replacing the short tags wherever they occur.

Bob McConnell

--- End Message ---
--- Begin Message ---
i have a problem of reading values from excel file via
spreadsheet_excel_reader which is a php class used to manipulate excel
files.

$data = new Spreadsheet_Excel_Reader();
$data->setOutputEncoding('CP936');
$data->read("d:\\tmp.xls");
$rows=$data->sheets[0]['numRows'];
$cell = $data->sheets[0]['cells'][1][1];

if i type many rows,say 1000, in the tmp.xls, it can read, $rows shows 1000,
however, 1000 rows of data are copied from another excel file and these
cells may have different background or other changes that differ from normal
cells, it fails to read.the variable $rows shows nothing....what i can do
now is to split these data into small groups, small enough to be read, it
really takes plenty of time.


i dont know why, has somebody met this problem ever?

--- End Message ---
--- Begin Message ---
On Tue, 2010-03-16 at 20:16 +0800, I am on the top of the world!
Borlange University wrote:

> i have a problem of reading values from excel file via
> spreadsheet_excel_reader which is a php class used to manipulate excel
> files.
> 
> $data = new Spreadsheet_Excel_Reader();
> $data->setOutputEncoding('CP936');
> $data->read("d:\\tmp.xls");
> $rows=$data->sheets[0]['numRows'];
> $cell = $data->sheets[0]['cells'][1][1];
> 
> if i type many rows,say 1000, in the tmp.xls, it can read, $rows shows 1000,
> however, 1000 rows of data are copied from another excel file and these
> cells may have different background or other changes that differ from normal
> cells, it fails to read.the variable $rows shows nothing....what i can do
> now is to split these data into small groups, small enough to be read, it
> really takes plenty of time.
> 
> 
> i dont know why, has somebody met this problem ever?


If it's just the data you need, try using a csv file instead. The Excel
format is closed, and as such, the PHP classes won't have full support
for all of it's features. It seems like formatting is causing the data
to be written to the spreadsheet differently maybe.

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



--- End Message ---
--- Begin Message ---
On 15 March 2010 00:27, Rick Pasotto <r...@niof.net> wrote:
> On Sun, Mar 14, 2010 at 08:40:51PM +0000, Ashley Sheridan wrote:
>> On Sun, 2010-03-14 at 16:41 -0400, Rick Pasotto wrote:
>>
>> > On Sun, Mar 14, 2010 at 06:13:24PM +0000, Ashley Sheridan wrote:
>> > > On Sun, 2010-03-14 at 14:15 -0400, Rick Pasotto wrote:
>> > >
>> > > > Has cli php changed recently?
>> > > >
>> > > > I've got a php script (script1) that creates a php script (script2) by
>> > > > opening a file and then writing to it. When I try to run it from the
>> > > > command line script1 is simply copied to stdout. When I run it from the
>> > > > browser it works as expected. The directory has 777 permissions so that
>> > > > should not be the problem.
>> > > >
>> > > > Any ideas?
>> > >
>> > > How are you running it from the command line?
>> >
>> > Is there more than one way? I suppose with and without the -f could
>> > count as two ways, but the man page says without defaults to with so
>> > they're really the same.
>>
>> Well you havn't given an example, and just say you're calling the script
>> from command line and it's outputting the script there. Are you maybe
>> just calling the php file without calling php first?
>
> Of course not. php scripts are not executable. If I had tried to execute
> it directly the shell would have told me that. If I had then set the
> executable bit the shell would have tried to execute the contents of the
> file and the shell would have given several error messages.
>
> I repeat: is there more than one way to run a php script from the cli?
>
> --
> "Feeling sorry for yourself, and you present condition, is not only a
>  waste of energy but the worst habit you could possibly have."
>        -- Dale Carnegie
>    Rick Pasotto    r...@niof.net    http://www.niof.net
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

Be careful. .BAT files are not executable, but you don't need to put
the command line processor in front do you?

You can quite easily turn ...

C:\PHP5\PHP.exe -f C:\Pathed\Directory\Script.php -- -script_arg1 -script_arg2

into

Script -script_arg1 -script_arg2

No php.exe, no .php, no -f

See http://docs.php.net/manual/en/install.windows.commandline.php

You can even turn php scripts into filters ...

Script -script_arg1 -script_arg2 | Script2 -script_arg1 -script_arg2

sort of thing.




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

--- End Message ---

Reply via email to