php-general Digest 8 May 2013 02:38:45 -0000 Issue 8221
Topics (messages 321023 through 321030):
Re: filesize question
321023 by: marco.behnke.biz
321030 by: tamouse mailing lists
Problems with array_push?
321024 by: Jay Blanchard
321025 by: Stuart Dallas
321026 by: Larry Martell
321027 by: Jay Blanchard
array_map() with multiple callback functions
321028 by: George Langley
321029 by: Alex Nikitin
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 ---
> Curtis Maurand <cur...@maurand.com> hat am 7. Mai 2013 um 15:16 geschrieben:
>
>
> Hello,
> I'm feeding a filename to a php script on the command line (command line
> program). I run the following against it:
>
> $inputline = fread($inputfile, filesize($argv[1]));
mayve
$inputline = fread($inputfile, filesize($inputfile));
>
> I'm getting an error complaining that the second parameter can't be '0'
>
> any ideas?
>
> thanks,
> Curtis
>
>
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
--
Marco Behnke
Dipl. Informatiker (FH), SAE Audio Engineer Diploma
Zend Certified Engineer PHP 5.3
Tel.: 0174 / 9722336
e-Mail: ma...@behnke.biz
Softwaretechnik Behnke
Heinrich-Heine-Str. 7D
21218 Seevetal
http://www.behnke.biz
--- End Message ---
--- Begin Message ---
On Tue, May 7, 2013 at 8:16 AM, Curtis Maurand <cur...@maurand.com> wrote:
> Hello,
> I'm feeding a filename to a php script on the command line (command line
> program). I run the following against it:
>
> $inputline = fread($inputfile, filesize($argv[1]));
>
> I'm getting an error complaining that the second parameter can't be '0'
The thing to look for, is how did you get $inputfile out of the
command line, and why you'd expect the file name to be in $argv[1] at
that point? Marco's suggestion isn't really going to work as
$inputfile will be a file handle, and filesize() needs the name of the
file. Maybe want to give us a wider look at what your code is doing?
Generically, you can wrap this up as:
function binread_file($filename)
{
$handle = fopen($filename,'rb');
if (FALSE === $handle) die("Unable to open $filename");
$contents = fread($handle, filesize($filename));
if (FALSE === $contents) die("Unable to read $filename");
return $contents;
}
--- End Message ---
--- Begin Message ---
I know that I must be missing something really ridiculous, but when I
print_r these arrays they are empty. I have confirmed that $arrayElement
is properly formed, it just seems that array_push is not working. I know
I have done this before, but I cannot find my older code. Can someone
clear the mud from my eyes?
$issueDifferently = array();
$issueProblem = array();
$issueComment = array();
function addToArray($id, $namecred, $product, $level, $type, $message) {
$arrayElement = $id
.'|'.$namecred.'|'.$product.'|'.$level.'|'.$type.'|'.$message;
if('DoDifferently' == $type) {
array_push($issueDifferently, $arrayElement);
} elseif ('Problem' == $type){
array_push($issueProblem, $arrayElement);
} elseif ('Comments' == $type) {
array_push($issueComment, $arrayElement);
}
}
print_r($issueDifferently);
print_r($issueProblem);
print_r($issueComment);
--- End Message ---
--- Begin Message ---
Globals being used in a function.
-Stuart
On Tue, May 7, 2013 at 11:06 PM, Jay Blanchard
<jay.blanch...@sigmaphinothing.org> wrote:
> I know that I must be missing something really ridiculous, but when I
> print_r these arrays they are empty. I have confirmed that $arrayElement
> is properly formed, it just seems that array_push is not working. I know
> I have done this before, but I cannot find my older code. Can someone
> clear the mud from my eyes?
> $issueDifferently = array();
> $issueProblem = array();
> $issueComment = array();
> function addToArray($id, $namecred, $product, $level, $type, $message) {
> $arrayElement = $id
> .'|'.$namecred.'|'.$product.'|'.$level.'|'.$type.'|'.$message;
> if('DoDifferently' == $type) {
> array_push($issueDifferently, $arrayElement);
> } elseif ('Problem' == $type){
> array_push($issueProblem, $arrayElement);
> } elseif ('Comments' == $type) {
> array_push($issueComment, $arrayElement);
> }
> }
> print_r($issueDifferently);
> print_r($issueProblem);
> print_r($issueComment);
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
--- End Message ---
--- Begin Message ---
On Tue, May 7, 2013 at 3:06 PM, Jay Blanchard
<jay.blanch...@sigmaphinothing.org> wrote:
> I know that I must be missing something really ridiculous, but when I
> print_r these arrays they are empty. I have confirmed that $arrayElement is
> properly formed, it just seems that array_push is not working. I know I have
> done this before, but I cannot find my older code. Can someone clear the mud
> from my eyes?
>
> $issueDifferently = array();
> $issueProblem = array();
> $issueComment = array();
>
> function addToArray($id, $namecred, $product, $level, $type, $message) {
> $arrayElement = $id
> .'|'.$namecred.'|'.$product.'|'.$level.'|'.$type.'|'.$message;
>
> if('DoDifferently' == $type) {
> array_push($issueDifferently, $arrayElement);
> } elseif ('Problem' == $type){
> array_push($issueProblem, $arrayElement);
> } elseif ('Comments' == $type) {
> array_push($issueComment, $arrayElement);
> }
> }
> print_r($issueDifferently);
> print_r($issueProblem);
> print_r($issueComment);
You have to declare the arrays as global inside your function.
--- End Message ---
--- Begin Message ---
[snip]Globals being used in a function. [/snip]
*smacks forehead*
--- End Message ---
--- Begin Message ---
Hi all. I want to apply strtolower() AND trim() to all items in an array. But I
don't see a way to call multiple callbacks with the array_map() function.
Are my two choices the following:
// 1) nesting two array_map() calls
$cleanData = array_map('trim',(array_map('strtolower',$rawData)));
// 2) call my own function with array_walk()
$cleanData = array_walk('myCleaner',$rawData);
function myCleaner($passedData){
$cleanData = array_map('strtolower',$passedData);
$cleanData = array_map('trim',$cleanData);
}
//(Of course, wouldn't bother with a function, just to call array_map twice...)
Just seeing if there's a better way than having to go through the array twice
to apply each callback separately. Thanks,
--- End Message ---
--- Begin Message ---
Something like:
$cleanData = array_map(function($str){return strtolower(trim($str));},
$passedData);
--
The trouble with programmers is that you can never tell what a
programmer is doing until it’s too late. ~Seymour Cray
On Tue, May 7, 2013 at 4:29 PM, George Langley <george.lang...@shaw.ca> wrote:
> Hi all. I want to apply strtolower() AND trim() to all items in an array. But
> I don't see a way to call multiple callbacks with the array_map() function.
> Are my two choices the following:
>
> // 1) nesting two array_map() calls
> $cleanData = array_map('trim',(array_map('strtolower',$rawData)));
>
>
> // 2) call my own function with array_walk()
> $cleanData = array_walk('myCleaner',$rawData);
>
> function myCleaner($passedData){
> $cleanData = array_map('strtolower',$passedData);
> $cleanData = array_map('trim',$cleanData);
> }
> //(Of course, wouldn't bother with a function, just to call array_map
> twice...)
>
> Just seeing if there's a better way than having to go through the array twice
> to apply each callback separately. Thanks,
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
--- End Message ---