[PHP] newbe question

2009-03-25 Thread Andres Gonzalez

Hi,

I want to learn PHP so I started using it for all of my general purpose 
scripts. The general format of my scripts are like this:


#!/usr/bin/php


When I run my scripts and I have an echo (or print) at the end of the 
script to print out the results of the script, I get an extra line feed 
printed out. It seems that I can use this:


echo " bla bla bla with no terminating line feed";

and I will not get a line feed. But when I use the echo at the end of 
the script I get a terminating line feed. Is this correct or am I 
misinterpreting this?


Does echo and print always terminate the string with a \n ?
The function manual does not seem to mention anything about this.

thanks,

-Andres



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



Re: [PHP] newbe question

2009-03-25 Thread Andres Gonzalez
I just figured this out. 


It all depends on what is AFTER the last ?> tag.

If I do not have extra line feeds they are not printed.

Wow...

thanks,

-Andres


Andres Gonzalez wrote:

Hi,

I want to learn PHP so I started using it for all of my general 
purpose scripts. The general format of my scripts are like this:


#!/usr/bin/php


When I run my scripts and I have an echo (or print) at the end of the 
script to print out the results of the script, I get an extra line 
feed printed out. It seems that I can use this:


echo " bla bla bla with no terminating line feed";

and I will not get a line feed. But when I use the echo at the end of 
the script I get a terminating line feed. Is this correct or am I 
misinterpreting this?


Does echo and print always terminate the string with a \n ?
The function manual does not seem to mention anything about this.

thanks,

-Andres





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



Re: [PHP] newbe question

2009-03-25 Thread Andres Gonzalez

thanks for your response kyle, I did not realize that.

-Andres


kyle.smith wrote:

I'm not sure it will resolve your issue, but the closing ?> is not a
requirement and will eliminate any chance of you adding whitespace to
the end of your scripts:

#!/usr/bin/php
echo "I'm some script output!"


is a valid script.


---
Kyle Smith
Unix Systems Administrator
Inforonics, LLC
 


-Original Message-
From: Andres Gonzalez [mailto:and...@packetstorm.com] 
Sent: Wednesday, March 25, 2009 11:29 AM

To: php-general@lists.php.net
Subject: [PHP] newbe question

Hi,

I want to learn PHP so I started using it for all of my general purpose
scripts. The general format of my scripts are like this:

#!/usr/bin/php


When I run my scripts and I have an echo (or print) at the end of the
script to print out the results of the script, I get an extra line feed
printed out. It seems that I can use this:

echo " bla bla bla with no terminating line feed";

and I will not get a line feed. But when I use the echo at the end of
the script I get a terminating line feed. Is this correct or am I
misinterpreting this?

Does echo and print always terminate the string with a \n ?
The function manual does not seem to mention anything about this.

thanks,

-Andres



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


  


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



[PHP] problems with loaded extensions

2009-04-08 Thread Andres Gonzalez

Hi,

I have got an extension loaded in all three of my php config files (in 
cli, in cgi, and in apache2 directories).  The functions in the 
extension are all accessible when running test scripts from the command 
line, like:


php init.php

for example, in the init.php file I have calls to several of the 
functions in my loaded extension. I also can print out the functions 
like this:


print_r(get_loaded_extensions());
print_r(get_extension_funcs("vrad"));

However, when I run these thru apache, all calls to the functions in my 
loaded extension fail even though the extension is present. If I do


print_r(get_loaded_extensions());

I see my loaded extension "vrad" printed out as expected indicating it 
is loaded. If I run:


if (extension_loaded("vrad"))

it comes back true which further indicates that the extension is indeed 
loaded.


But if I call using apache any of the functions in the loaded extension, 
or if I call: 


print_r(get_extension_funcs("vrad"));

all I get is a blank white page with no errors.

I would think that as long as the extension is loaded in both the cli 
php.ini and the apache2 php.ini, I would get the same results from the 
loaded extension. Any idea why it work thru the cli and not apache?


Thanks,

-Andres

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



[PHP] multi-dimensional arrays

2009-04-13 Thread Andres Gonzalez

Hi,

I am learning PHP and have a simple question.
I have a input string in this form:

xxx    xx  x  xx   xxx
xx  x   x  xxx  xx  xx
.
.
.
xx  xxx  xx    xx   xx

each line has 6 words of various lengths, all separated by white space.
the input string can have any number of lines

I want to put this into a multi-dimensional array, each line an array 
that is an element of an outer array.


I have tried various ways to do this--I have used explode() and 
array_filter() and can get a single line parsed and into an array but I 
am having problems getting a well formed 2 dim array.


What is the easiest way to do this? With all of the PHP array functions, 
there should be an very straight forward way to do this.


Any help would be appreciated.

-Andres




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



Re: [PHP] multi-dimensional arrays

2009-04-13 Thread Andres Gonzalez

I was having the same problem. The second way was what I was looking for.

Thank you so much for your help--I did not know about preg_match_all().

very coolthanks again.

-Andres


Shawn McKenzie wrote:

Shawn McKenzie wrote:
  

Well in your approach you get a bunch of empty elements where the spaces
are.  Here are two ways but I'm sure one preg_match_all() without the
explodes and loop could do it (some guru will show us):

//one way
$text = 'xxx    xx  x  xx   xxx
xx  x   x  xxx  xx  xx
xx  xxx  xx    xx   xx';

$lines = explode(PHP_EOL, $text);

foreach($lines as $line) {
$temp = explode(' ', $line);
$result[] = array_filter($temp, 'reduce');
}
function reduce($var) {
return !empty($var);
}
print_r($result);


Array
(
[0] => Array
(
[0] => xxx
[2] => 
[4] => xx
[6] => x
[8] => xx
[11] => xxx
)

[1] => Array
(
[0] => xx
[2] => x
[5] => x
[7] => xxx
[9] => xx
[11] => xx
)

[2] => Array
(
[0] => xx
[2] => xxx
[4] => xx
[6] => 
[8] => xx
[11] => xx
)

)
  

//another way
$text = 'xxx    xx  x  xx   xxx
xx  x   x  xxx  xx  xx
xx  xxx  xx    xx   xx';

$lines = explode(PHP_EOL, $text);

foreach($lines as $line) {
preg_match_all('|([^\s]+)+|', $line, $matches);
$result[] = $matches[1];
}
print_r($result);


Array
(
[0] => Array
(
[0] => xxx
[1] => 
[2] => xx
[3] => x
[4] => xx
[5] => xxx
)

[1] => Array
(
[0] => xx
[1] => x
[2] => x
[3] => xxx
[4] => xx
[5] => xx
)

[2] => Array
(
[0] => xx
[1] => xxx
[2] => xx
[3] => 
[4] => xx
[5] => xx
)

)

There is a difference in the key numbering though if that is important.

  


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



[PHP] modifying within foreach

2009-06-23 Thread Andres Gonzalez

In the following example:

foreach ($results as $key => $item)  {

   //bla bla bla -- unset some of the $items

}

I want to modify $results within the foreach. In other words,
during a given pass of this iteration, I want to delete some
of the items based on particular conditions. Then on the next
pass thru the foreach, I want $results to be the newer, modified
array.

This does not seem to work. It appears that the foreach statement
is implemented such that $results is read into memory at the start
so that any modifications I make to it during a given pass, are ignored
on the next pass. Is this true?

If so, is there a way that I can tell the foreach statement to re-read the
array $results?  Or am I just going against the grain here?

-Andres


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



Re: [PHP] modifying within foreach

2009-06-23 Thread Andres Gonzalez

I do not want to delete the whole array, only a particular $item.
given this $results array:

Array
(
["key1"] => Array
(
[0] => value1
[1] => value2
[2] => value 3
(
["key2"] => Array
(
[0] => value4
[1] => value5
[2] => value6
)
)

It is a value item that I want to delete based on a particular criteria.
In each pass I may delete a value item. However, it seems that each
subsequent pass operates on the original $results array and not
the modified one.

-Andres



Daevid Vincent wrote:
 foreach ($results as $key => $item) 
 {

if ($item == 'foo') unset($results[$key]);
 }

  

-Original Message-
From: Andres Gonzalez [mailto:and...@packetstorm.com] 
Sent: Tuesday, June 23, 2009 11:27 AM

To: php-general@lists.php.net
Subject: [PHP] modifying within foreach

In the following example:

foreach ($results as $key => $item)  {

//bla bla bla -- unset some of the $items

}

I want to modify $results within the foreach. In other words,
during a given pass of this iteration, I want to delete some
of the items based on particular conditions. Then on the next
pass thru the foreach, I want $results to be the newer, modified
array.

This does not seem to work. It appears that the foreach statement
is implemented such that $results is read into memory at the start
so that any modifications I make to it during a given pass, 
are ignored

on the next pass. Is this true?

If so, is there a way that I can tell the foreach statement 
to re-read the

array $results?  Or am I just going against the grain here?

-Andres


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





  


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



Re: [PHP] modifying within foreach

2009-06-23 Thread Andres Gonzalez

Thanks guys--passing by reference solved my problem. I was not aware
that the foreach statement works on a copy.  This was explained in the
online documentation.   Duh!!

Thanks again,

-Andres



Ashley Sheridan wrote:

On Tue, 2009-06-23 at 12:56 -0600, kirk.john...@zootweb.com wrote:
  

Andres Gonzalez  wrote on 06/23/2009 12:26:38 PM:



I want to modify $results within the foreach. In other words,
during a given pass of this iteration, I want to delete some
of the items based on particular conditions. Then on the next
pass thru the foreach, I want $results to be the newer, modified
array.

This does not seem to work. It appears that the foreach statement
is implemented such that $results is read into memory at the start
so that any modifications I make to it during a given pass, are ignored
on the next pass. Is this true?
  
foreach works on a copy of an array, so the behavior you saw is expected. 
See the online manual.


You could use a while loop, or, instead of unset-ing elements of $results, 
store the elements you want to keep into a new array.


Kirk



What about passing it by reference?

foreach($results as &$key => &$item)
{
// modify items here
}

Thanks
Ash
www.ashleysheridan.co.uk

  


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



[PHP] removing an array from a compound array

2009-07-01 Thread Andres Gonzalez
I have a compound array, that is, an array of an array of an array, etc, 
that is about 5 arrays
deep. I currently search thru all of these arrays, and based on some 
criteria, I want to delete

one of the arrays (along with all of its sub-arrays) in the middle.

What is the easiest way to delete such an "embedded" array?

array_splice() looked like a possibility, however, it requires that I 
specify the array

for removal by using offsets which seems odd to me.

Isn't there a way to remove array A from array B?

Thanks,

-Andres

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



Re: [PHP] removing an array from a compound array

2009-07-02 Thread Andres Gonzalez

Duh! I should have known that.

I actually tried that and had a problem so I thought unset() would not work
on an array. Guess that problem was elsewhere.

Thanks for the responses...

-Andres



Ford, Mike wrote:

-Original Message-
From: Andres Gonzalez [mailto:and...@packetstorm.com]
Sent: 02 July 2009 00:46
To: php-general@lists.php.net
Subject: [PHP] removing an array from a compound array

I have a compound array, that is, an array of an array of an array,
etc,
that is about 5 arrays
deep. I currently search thru all of these arrays, and based on some
criteria, I want to delete
one of the arrays (along with all of its sub-arrays) in the middle.

What is the easiest way to delete such an "embedded" array?



If you know all the keys leading to the subarray you want to remove
(which you probably do if you've just searched your way to it), then a
simple unset() should work, similar to:

Unset($array[$key1][$key2][$key3]);


Cheers!

Mike

 --
Mike Ford,  Electronic Information Developer,
C507, Leeds Metropolitan University, 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

  


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



[PHP] file_put_contents problem

2009-09-14 Thread Andres Gonzalez

I have read in the contents of a file using file_get_contents. I can verify
that the data has actually been read in by echoing its contents.

But then if I do this:

$ret = file_put_contents("/tmp/bla", $bk);

The return value gives the correct size of string $bk, and the file /tmp/bla
is created in /tmp, but the length is 0.

Why are not the contents written to the file?

-Andres

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



Re: [PHP] Re: file_put_contents problem

2009-09-14 Thread Andres Gonzalez
This is on a Ubuntu 9.04 box. I did not try to open the file but just 
listing out
the directory gives the size and it is 0.  If I try to cat out the 
contents, there is

nothing (I guess that does an open on it)

-Andres



Ralph Deffke wrote:

it would be interesting on what os u are working as well. did u try to open
the file?
on windows often a file is reported as 0 bytes as of failing the refresh in
explorer.

ralph_def...@yahoo.de


"Andres Gonzalez"  wrote in message
news:4aae510e.8030...@packetstorm.com...
  

I have read in the contents of a file using file_get_contents. I can


verify
  

that the data has actually been read in by echoing its contents.

But then if I do this:

$ret = file_put_contents("/tmp/bla", $bk);

The return value gives the correct size of string $bk, and the file


/tmp/bla
  

is created in /tmp, but the length is 0.

Why are not the contents written to the file?

-Andres





  


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



Re: [PHP] file_put_contents problem

2009-09-14 Thread Andres Gonzalez

thank you for your responses.

This appears to be a CodeIgniter  problem because everything
of course works fine from a command line script. I will post
a question on their forum.

Thanks again.

-Andres



Jim Lucas wrote:

Andres Gonzalez wrote:
  

I have read in the contents of a file using file_get_contents. I can verify
that the data has actually been read in by echoing its contents.

But then if I do this:

$ret = file_put_contents("/tmp/bla", $bk);

The return value gives the correct size of string $bk, and the file
/tmp/bla
is created in /tmp, but the length is 0.

Why are not the contents written to the file?

-Andres




We will need to see a little more code before we can make assumptions.

Jim


  


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



[PHP] php.ini in cgi vs php.ini in cli

2009-09-14 Thread Andres Gonzalez
In the php configurations directories /etc/php5, there are 2 
subdirectories, one for

cgi and one for cli.  There is a php.ini file in each of these directories.

What would cause a difference of behavior in these 2 environments with 
the php.ini

exactly the same in each directory??

I have a command line script that consequently uses the cli version. 
This script works
just fine in that it can access API function in modules that are loaded 
via cli/php.ini


However, when executing in the cgi environment, I get a "call to 
undefined function" error

even though my 2 php.ini files are exactly the same.

Any idea what is causing this?

thanks,

-Andres

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



Re: [PHP] php.ini in cgi vs php.ini in cli

2009-09-15 Thread Andres Gonzalez

Lars,

Thank you for your response. The function that raised this error is from 
my own
extension module. I was not aware of phpinfo() and your suggestion to 
run it helped
me resolve this issue. Turns out my CGI version is NOT using cgi/php.ini 
but is using

apache2/php.ini instead.

Thanks again for your help--you deserve a raise. :-)

-Andres





Lars Torben Wilson wrote:

On Mon, 14 Sep 2009 18:21:11 -0400
Andres Gonzalez  wrote:

  
In the php configurations directories /etc/php5, there are 2 
subdirectories, one for

cgi and one for cli.  There is a php.ini file in each of these
directories.

What would cause a difference of behavior in these 2 environments
with the php.ini
exactly the same in each directory??

I have a command line script that consequently uses the cli version. 
This script works

just fine in that it can access API function in modules that are
loaded via cli/php.ini

However, when executing in the cgi environment, I get a "call to 
undefined function" error

even though my 2 php.ini files are exactly the same.

Any idea what is causing this?

thanks,

-Andres




Hi Andres,

When asking this kind of question, it would be very helpful if you
would tell us *which* function raised this error.

My first thought is that you tried to call a function which was
compiled in to the CLI version but not the CGI. What does phpinfo()
show when run under each?


Torben

  


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



[PHP] moving to quad core

2009-09-15 Thread Andres Gonzalez
I have an application developed that uses alot of PHP. Currently, it is 
running on a Ubuntu 8.04 , single core CPU host.  We are moving to a 
quad core host for this application.


Is there anything special that I need to do to configure PHP to run on a 
quad core host? I noticed that my current single core system has PHP 
configured with Thread Safety disabled (as reported from phpinfo()).  
Does that need to be enabled to run in a multi-core environment?


Any other suggestions for configuring PHP for multi-core use?

Thanks,

-Andres

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



[PHP] PHP and javascript

2010-01-15 Thread Andres Gonzalez
How do I call PHP code that will run server side, from javascript code 
that is running client side?


I have a lot of PHP server side code written and working within 
CodeIgniter.  Now, my project
has changed and (for reasons unimportant to this discussion) we are now 
NOT going to
use apache and CodeIgniter, but instead, we are going to have to use an 
http server that does
not support PHP internally.  But I want to reuse my original PHP code. 
So I am thinking that I
can execute the PHP code via a command line interface using the PHP cli 
interface instead of
the PHP cgi interface. But, I will have to initiate this serversid call 
via javascript code running

on the client.

I know...kind of convoluted. But how would one do this if necessary?

-Andres

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



[PHP] editing a file

2010-05-24 Thread Andres Gonzalez
I have a large C source file that is generated by a separate 
source-generating program. When the generated src file is compiled, it 
produces tons of warnings. I want to edit the generated src file and 
delete the offending lines.


What is the easiest way using a PHP script to read in a file, search for 
a particular signature, and delete a couple of lines? Seems like this 
would be very easy in PHP.


Thanks,

-Andres

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



Re: [PHP] editing a file

2010-05-24 Thread Andres Gonzalez

thank you Rene, that is the start I needed.

-Andres


Rene Veerman wrote:

On Mon, May 24, 2010 at 11:16 PM, Andres Gonzalez
 wrote:
  

I have a large C source file that is generated by a separate
source-generating program. When the generated src file is compiled, it
produces tons of warnings. I want to edit the generated src file and delete
the offending lines.

What is the easiest way using a PHP script to read in a file, search for a
particular signature, and delete a couple of lines? Seems like this would be
very easy in PHP.



file_get_contents() to get the file into a $string.

preg_match_all(,,$matches) to get to what you need,

str_replace() to replace $matches with your chosen replacements

and there you are :)

file_put_contents() to save the results..

  

Thanks,

-Andres

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







  


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



[PHP] howto get pgUp, pgDn, delete, home and end keycodes in CLI PHP script

2012-05-04 Thread Andres Gonzalez
I am trying to code a CLI PHP script that will give me the keycodes for 
these (and other) keyboard keys. I want to basically block until the 
user presses a single key, then I want to process that event without the 
user having to press the Enter key after pressing a single key.


I have tried several approaches but with no success.  Using fopen() to 
open stdin, and fgetc() will give me the regular keys but requires the 
user to press the Enter key after the initial key is pressed. When I 
press the the PgDw key for example, those routines return a single 
character string even though the stty echos a 5 character string (using 
PgDw echos "^[[6~")


I have tried other approaches using bash read commands to get a single 
character but will little success also.


Anybody here know how to do this?

Thanks,

-Andres

|
|

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



Re: [PHP] howto get pgUp, pgDn, delete, home and end keycodes in CLI PHP script

2012-05-04 Thread Andres Gonzalez

David,

Thank you for your response.

The code does not run on my box. I get an undefined variable error on the:
if ($buffer != "") {
line.

Also, I need the code to block until the user presses a single key. 
Plus, the fgets() routine does not return extended codes for pgUp, pgDn, 
etc, only codes for regular keys.


-Andres




David OBrien wrote:

?

On Fri, May 4, 2012 at 10:48 AM, Andres Gonzalez 
mailto:and...@packetstorm.com>> wrote:


I am trying to code a CLI PHP script that will give me the
keycodes for these (and other) keyboard keys. I want to basically
block until the user presses a single key, then I want to process
that event without the user having to press the Enter key after
pressing a single key.

I have tried several approaches but with no success. Using fopen()
to open stdin, and fgetc() will give me the regular keys but
requires the user to press the Enter key after the initial key is
pressed. When I press the the PgDw key for example, those routines
return a single character string even though the stty echos a 5
character string (using PgDw echos "^[[6~")

I have tried other approaches using bash read commands to get a
single character but will little success also.

Anybody here know how to do this?

Thanks,

-Andres

|
|

-- 
PHP General Mailing List (http://www.php.net/)

To unsubscribe, visit: http://www.php.net/unsub.php


I think something like this would work

$running = true;
$fp = fopen("php://stdin","r"); //open direct input stream for reading
stream_set_blocking($fp,0); //set non-blocking mode

while ($running) {
while (($buf = fgets($fp, 4096)) != false) {
$buffer .= $buf;
}
if ($buffer != "") {
switch ($buffer) {
case " ": { //exit on space key
exit;
}
default: {
//space not pressed
}
}
$buffer = ""; //empty buffer
}




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



Re: [PHP] howto get pgUp, pgDn, delete, home and end keycodes in CLI PHP script

2012-05-04 Thread Andres Gonzalez

Thank you for your reply Stuart, I will look at ncurses extensions.

-Andres


Stuart Dallas wrote:

On 4 May 2012, at 15:48, Andres Gonzalez wrote:

  

I am trying to code a CLI PHP script that will give me the keycodes for these 
(and other) keyboard keys. I want to basically block until the user presses a 
single key, then I want to process that event without the user having to press 
the Enter key after pressing a single key.

I have tried several approaches but with no success.  Using fopen() to open stdin, and 
fgetc() will give me the regular keys but requires the user to press the Enter key after 
the initial key is pressed. When I press the the PgDw key for example, those routines 
return a single character string even though the stty echos a 5 character string (using 
PgDw echos "^[[6~")

I have tried other approaches using bash read commands to get a single 
character but will little success also.

Anybody here know how to do this?



As far as I know you can't do this through any of the built-in functions. 
However, the ncurses extension may give you what you need: 
http://php.net/ncurses

-Stuart

  


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