[PHP] LAMP jobs

2003-11-20 Thread Susan Ator
It seems like this question came up before. Is there a resource for people
looking for jobs working with open source products (LAMP specifically)?

Thanks,

susan

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



RE: [PHP] Having fits with input to array

2003-11-17 Thread Susan Ator
Hm... I should clarify this some more. This is the result of $Array2:

Array ( 
[0] = Array (
  [0] = 15083
  [1] = bash
  [2] = S
  [3] = 4380
  [4] = 10:31
  [5] = 000
  [6] = sator
  [7] = 00:00:00
  [8] = -bash 
  )
[1] = Array (
  [0] = 15126
  [1] = bash
  [2] = S
  [3] = 4380
  [4] = 10:31
  [5] = 000
  [6] = sator
  [7] = 00:00:00
  [8] = -bash
  )
[2] = Array (
  [0] = etc...
  )
) 

What I need is to be able to assign a variable to $Array2[0] - [0] so for
the first one it would be:

  $var0 = 15083
  $var1 = bash
  $var2 = S
  $var3 = 4380
  etc...

How do I get to this point?

Susan

-Original Message-
From: Susan Ator 
Sent: Friday, November 14, 2003 6:35 PM
To: 'CPT John W. Holmes '; ''Lowell Allen' '; 'PHP '
Subject: RE: [PHP] Having fits with input to array


Actually, what I need to do is:

  $var1 = $Array2[1]
  $var2 = $Array2[2]
  etc...

but I just seem to get

  Array

as the output of $var1, $var2, etc...

susan

-Original Message-
From: CPT John W. Holmes
To: Susan Ator; 'Lowell Allen'; PHP
Sent: 11/14/03 4:01 PM
Subject: Re: [PHP] Having fits with input to array

From: Susan Ator [EMAIL PROTECTED]

 Perfect! That did exactly what I needed.

Good...

 Now, *ahem*, I thought I knew how to assign variables to the elements
in
 Array2 but *cough* I'm somewhat befuddled. I've not been able to find
 anything in the online php manual. Could you point me in the right
direction
 for that?

Not sure I'm following you, but

$Array2[] = $somvariable;

will add the value of $somevariable to the next element of $Array2.

Can you explain a little more what you want if that's not it.

---John Holmes...

-- 
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



FW: [PHP] Having fits with input to array

2003-11-17 Thread Susan Ator
Sorry, forgot to post to the list.

sa

-Original Message-
From: Susan Ator 
Sent: Monday, November 17, 2003 11:12 AM
To: 'CPT John W. Holmes'
Subject: RE: [PHP] Having fits with input to array


D'oh. You're right. I have a tendency to do things the hard way. That's what
comes of getting too focused on doing things a certain way. :P

Thanks, I think that does it for me!

susan

-Original Message-
From: CPT John W. Holmes [mailto:[EMAIL PROTECTED]
Sent: Monday, November 17, 2003 11:12 AM
To: Susan Ator; ''Lowell Allen' '; 'PHP '
Subject: Re: [PHP] Having fits with input to array


- Original Message - 
From: Susan Ator [EMAIL PROTECTED]

 Hm... I should clarify this some more. This is the result of $Array2:

 Array (
 [0] = Array (
   [0] = 15083
[snip]
 What I need is to be able to assign a variable to $Array2[0] - [0] so for
 the first one it would be:

   $var0 = 15083
[snip]
 How do I get to this point?

The question is, why do you need to get to that point? I think you're doing
to much work. You already have the variable $Array2[0][0] that you can use
anywhere, why do you need to assign it to yet another variable.

Maybe you just need to look at foreach() for looping through the array?

What was your point of getting $var0, $var1, $var2, etc... there's probably
a better method for whatever you're doing.

---John Holmes...

-- 
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] Having fits with input to array

2003-11-14 Thread Susan Ator
I have a series of commands like so (with different programs on each line):

display_pgm(bash);

Here is the bare bones of the function 'display_pgm':

function display_pgm ($pgm) {
$cmd =  -C $pgm --no-headers -o
pid,fname,state,vsz,start_time,flag,user,cputime,args --cols 200;
$ps = `ps $cmd`;
$ps2 = ereg_replace(\n, ,, $ps);

eval(\$psArray = array(\$ps2););
print_r($psArray);
}

If I can't get this part to work the rest of the function is a no-go. When I
do this I get only one element in my array instead of the 3-4 I should be
getting. I'm using bash for testing since I know that will always give a
return.

I've also tried:
eval(\$psArray = array(\$ps2\););
and
eval(\$psArray = array($ps2);); - This one gives me a parse error
(Parse error: parse error, unexpected T_STRING, expecting ')' in
/var/www/html/ps.php(25) : eval()'d code on line 1)

When I have used the same eval in another page I get each part separated by
the comma as a separate element in the array. What in the world am I doing
wrong?

susan

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



[PHP] Having fits with input to array

2003-11-14 Thread Susan Ator
I am sending this again as it seems like it didn't go the first time.


I have a series of commands like so (with different programs on each line):

display_pgm(bash);

Here is the bare bones of the function 'display_pgm':

function display_pgm ($pgm) {
$cmd =  -C $pgm --no-headers -o
pid,fname,state,vsz,start_time,flag,user,cputime,args --cols 200;
$ps = `ps $cmd`;
$ps2 = ereg_replace(\n, ,, $ps);

eval(\$psArray = array(\$ps2););
print_r($psArray);
}

If I can't get this part to work the rest of the function is a no-go. When I
do this I get only one element in my array instead of the 3-4 I should be
getting. I'm using bash for testing since I know that will always give a
return.

I've also tried:
eval(\$psArray = array(\$ps2\););
and
eval(\$psArray = array($ps2);); - This one gives me a parse error
(Parse error: parse error, unexpected T_STRING, expecting ')' in
/var/www/html/ps.php(25) : eval()'d code on line 1)

When I have used the same eval in another page I get each part separated by
the comma as a separate element in the array. What in the world am I doing
wrong?

susan

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



RE: [PHP] Having fits with input to array

2003-11-14 Thread Susan Ator
Well, my understanding is the array($ps2); bit takes care of that.

What I need to do is call the ps command with the options listed for each
program I'm interested in tracking, take each line output and treat it as an
element in an array. Then, for each array element I need to create another
array with each element in the line output as an array element.

For example, the command:

ps -C bash --no-headers -o fname,state,vsz,start_time,flag,user,cputime,args
--cols 200

gives me the output of:
bash S 4396 Nov13 000 sator 00:00:00 -bash
bash S 4392 Nov13 000 sator 00:00:00 -bash
bash S 4396 Nov13 000 sator 00:00:00 -bash

The array I end up with using this code (where $pgm is bash):

$cmd =  -C $pgm --no-headers -o
pid,fname,state,vsz,start_time,flag,user,cputime,args --cols 200;
$ps = `ps $cmd`;
$ps2 = ereg_replace(\n, ,, $ps);
eval(\$psArray = array(\$ps2););
print_r($psArray);

is:

Array ( [0] = bash sleeping 4396 Nov13 000 sator 00:00:00 -bash,bash
sleeping 4392 Nov13 000 sator 00:00:00 -bash,bash sleeping 4396 Nov13 000
sator 00:00:00 -bash )

where I need it to be:

Array (
[0] = bash S 4396 Nov13 000 sator 00:00:00 -bash
[1] = bash S 4392 Nov13 000 sator 00:00:00 -bash
[2] = bash S 4396 Nov13 000 sator 00:00:00 -bash
)

and the second array needs to be:

Array (
[0] = Array (
[0] = bash
[1] = S
[2] = 4396
[3] = Nov13
[4] = 000
[5] = sator
[6] = 00:00:00
[7] = -bash
)
etc...
)

THIS is what I am unable to do. Does anyone have any ideas?

susan

-Original Message-
From: Lowell Allen [mailto:[EMAIL PROTECTED]
Sent: Friday, November 14, 2003 12:16 PM
To: PHP
Subject: Re: [PHP] Having fits with input to array


For $psArray to be an array, shouldn't it be:

eval(\$psArray[] = array(\$ps2););

--
Lowell Allen

-- 
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] Having fits with input to array

2003-11-14 Thread Susan Ator
Perfect! That did exactly what I needed.

Now, *ahem*, I thought I knew how to assign variables to the elements in
Array2 but *cough* I'm somewhat befuddled. I've not been able to find
anything in the online php manual. Could you point me in the right direction
for that?

Thank you,

susan

-Original Message-
From: CPT John W. Holmes [mailto:[EMAIL PROTECTED]
Sent: Friday, November 14, 2003 3:00 PM
To: Susan Ator; 'Lowell Allen'; PHP
Subject: Re: [PHP] Having fits with input to array

$Array1 = array();
$Array2 = array();

$cmd =  -C $pgm --no-headers -o
pid,fname,state,vsz,start_time,flag,user,cputime,args --cols 200;
$ps = `ps $cmd`;
$Array1 = explode(\n,$ps);
foreach($Array1 as $line)
{ $Array2[] = explode( ,$line); }

print_r($Array1);
print_r($Array2);

---John Holmes...

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



RE: [PHP] Having fits with input to array

2003-11-14 Thread Susan Ator
Actually, what I need to do is:

  $var1 = $Array2[1]
  $var2 = $Array2[2]
  etc...

but I just seem to get

  Array

as the output of $var1, $var2, etc...

susan

-Original Message-
From: CPT John W. Holmes
To: Susan Ator; 'Lowell Allen'; PHP
Sent: 11/14/03 4:01 PM
Subject: Re: [PHP] Having fits with input to array

From: Susan Ator [EMAIL PROTECTED]

 Perfect! That did exactly what I needed.

Good...

 Now, *ahem*, I thought I knew how to assign variables to the elements
in
 Array2 but *cough* I'm somewhat befuddled. I've not been able to find
 anything in the online php manual. Could you point me in the right
direction
 for that?

Not sure I'm following you, but

$Array2[] = $somvariable;

will add the value of $somevariable to the next element of $Array2.

Can you explain a little more what you want if that's not it.

---John Holmes...

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



[PHP] Passing variables on the url and Macs

2003-11-12 Thread Susan Ator
Does anyone know of a problem on Macs (pre OSX) with passing variables on
the URL?

For example with the following url:

http://someplace.org/file.php?ID=idthingy=thingy

only

http://someplace.org/file.php

actually gets passed.

susan

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



RE: [PHP] Session output question

2003-10-22 Thread Susan Ator
Perfect. Thank you so much. That was exactly what I needed.

Susan

-Original Message-
From: CPT John W. Holmes [mailto:[EMAIL PROTECTED]
Sent: Wednesday, October 22, 2003 1:53 PM
To: Susan Ator; [EMAIL PROTECTED]
Subject: Re: [PHP] Session output question


From: Susan Ator [EMAIL PROTECTED]
 1) Is there any way to print out active sessions names?

 I have $_SESSION['SID'], $_SESSION['uid'], $_SESSION['msg']
 can I output the literal strings:
 $_SESSION['SID']
 $_SESSION['uid']
 $_SESSION['msg']

$keys = array_keys($_SESSION);

 2) Is there any way to use a variable in a session name?

 can I do:
 $msg=20031022
 $_SESSION[$msg.name] becomes $_SESSION['20031022name']

Just like that or $_SESSION[$msg.'name']. Same rules as making a string
anywhere else; that's all you're doing.

---John Holmes...

-- 
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] Session question

2003-10-14 Thread Susan Ator
What would cause the loss of a session in these circumstances:

php page with search form - session good
search form calls perl script
php page with search results - php wrapper for perl search form
displaying output - session good
php page gotten to from link on php search results page in perl
search form output - session lost | new SID set but SID cookie not displayed
when showing phpinfo. Same php page gotten to from another direction -
session good.

This is pretty slim as far as details go but it pretty much sums up the
problem.

Does anyone have any idea where the session information is getting hosed?

Thanks,

Susan

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



RE: [PHP] pad numbers

2003-10-10 Thread Susan Ator
The way I have done it is to check the length of the number and if it is 1
then add the 0 myself.

my $len = length($mm);
if ($len eq 1) { $mm = 0$mm; }

Susan

-Original Message-
From: Diana Castillo [mailto:[EMAIL PROTECTED]
Sent: Friday, October 10, 2003 10:45 AM
To: [EMAIL PROTECTED]
Subject: [PHP] pad numbers


is there a function to convert a number that has less than two digits into a
number with a leading zero?
for instance, to convert a 5 to 05 but to leave a 11 as 11
thanks,
Diana

-- 
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] File read and sort question

2003-10-06 Thread Susan Ator
I have a directory with an ever-changing number of files. Some will be
removed and others added on a continuing basis.

The files are ascii with the following layout:

SENDER Name
SUBJECT Subject line
RELEASE_DATE mm/dd/
RELEASE_TIME hh:mm

I can easily get a list of files and pull the necessary information. I need,
however to be able to sort by RELEASE_DATE *and* RELEASE_TIME

Philosophically, what is the best way to handle this? I'm hesitant to pull
all the information into an array and use ksort since there are, on average,
~1000 messages in this directory which need to be processed.

Susan

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



RE: [PHP] File read and sort question

2003-10-06 Thread Susan Ator
The problem with using a database is the files within the directory are
changing on, sometimes, a minute by minute basis. I think reading them into
the database then deleting them when they are deleted from the directory
would be a huge amount of overhead. No?

Something else which I did not make clear in my previous post; when the
files are removed from the directory I no longer want them displaying in my
web page.

Susan

-Original Message-
From: Robert Cummings [mailto:[EMAIL PROTECTED]
Sent: Monday, October 06, 2003 12:18 PM
To: Susan Ator
Cc: PHP-General
Subject: Re: [PHP] File read and sort question


On Mon, 2003-10-06 at 12:10, Susan Ator wrote:
 I have a directory with an ever-changing number of files. Some will be
 removed and others added on a continuing basis.
 
 The files are ascii with the following layout:
 
 SENDER Name
 SUBJECT Subject line
 RELEASE_DATE mm/dd/
 RELEASE_TIME hh:mm
 
 I can easily get a list of files and pull the necessary information. I
need,
 however to be able to sort by RELEASE_DATE *and* RELEASE_TIME
 
 Philosophically, what is the best way to handle this? I'm hesitant to pull
 all the information into an array and use ksort since there are, on
average,
 ~1000 messages in this directory which need to be processed.

Smells like a job for a database :)  Otherwise you'll need to either
read all the data in, or create another file heirarchy with the
appropriate redundancy to retrieve in sorted order, which incidentally
probably loads all the file names then sorts. Really it's a database,
database, database issue *grin*.

Cheers,
Rob.
-- 
..
| 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.  |
`'

-- 
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] File read and sort question

2003-10-06 Thread Susan Ator
I have no control over

1) file naming
2) file inclusion in the directory
3) file removal from the directory

This is all being handled through another program written in C.

So far I have been able to put the relevant info from each file into the
database then display with a simple order by.

Now, I'm attempting to get the correct flow for checking if the file is in
the database but not in the directory so I can delete it from the database.
Trial and error.

Susan

-Original Message-
From: Brad Pauly [mailto:[EMAIL PROTECTED]
Sent: Monday, October 06, 2003 1:06 PM
To: PHP-General
Subject: Re: [PHP] File read and sort question


Susan Ator wrote:

 The problem with using a database is the files within the directory are
 changing on, sometimes, a minute by minute basis. I think reading them
into
 the database then deleting them when they are deleted from the directory
 would be a huge amount of overhead. No?
 
 Something else which I did not make clear in my previous post; when the
 files are removed from the directory I no longer want them displaying in
my
 web page.

[snip]

 On Mon, 2003-10-06 at 12:10, Susan Ator wrote:
 
I have a directory with an ever-changing number of files. Some will be
removed and others added on a continuing basis.

The files are ascii with the following layout:

SENDER Name
SUBJECT Subject line
RELEASE_DATE mm/dd/
RELEASE_TIME hh:mm

I can easily get a list of files and pull the necessary information. I

Would it be possible to take advantage of the way the files are named? 
If you included the RELEASE_DATE and RELEASE_TIME in the name of the 
file it would save you the step of reading the files. Just getting the 
contents of the directory should provide all the information. Of course 
you would still need to put that in an array and sort it.

- Brad

-- 
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] $_SERVER['UNIQUE_ID'] question

2003-09-23 Thread Susan Ator
I have looked and cannot find any information on this particular variable.
How unique is this id and when does it get generated? I'm looking to use
this as a session identifier.

Susan

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



[PHP] is it possible to have the following URL?

2003-09-22 Thread Susan Ator
I am passing 3 pieces of information on every URL. For example:

https://url_location.org/page.php?SID=$SIDuid=$uidELEM_ID=$id


I need to be able to return to a previous page using an anchor tag like so:

https://url_locaion.org/prev_page.php#tag?SID=$SIDuid=$uidELEM_ID=$id

So far it doesn't work at all. Is this even possible? Just using the
javascript:history.go(-1) doesn't work in every browser.

susan

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



RE: [PHP] is it possible to have the following URL?

2003-09-22 Thread Susan Ator
Thank you so much. That worked perfectly. Don't know why I didn't think of
trying the anchor tag there.

susan

-Original Message-
From: Erwin Kerk [mailto:[EMAIL PROTECTED]
Sent: Monday, September 22, 2003 11:48 AM
To: [EMAIL PROTECTED]
Subject: Re: [PHP] is it possible to have the following URL?


This should work:

https://url_locaion.org/prev_page.php?SID=$SIDuid=$uidELEM_ID=$id#tag


Erwin

Susan Ator wrote:

I am passing 3 pieces of information on every URL. For example:

https://url_location.org/page.php?SID=$SIDuid=$uidELEM_ID=$id


I need to be able to return to a previous page using an anchor tag like so:

https://url_locaion.org/prev_page.php#tag?SID=$SIDuid=$uidELEM_ID=$id

So far it doesn't work at all. Is this even possible? Just using the
javascript:history.go(-1) doesn't work in every browser.

susan

  


-- 
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] How do I do this PERL in PHP?

2003-09-16 Thread Susan Ator
I have a text file with the following format:

TO name
SUBJECT stuff
MESSAGE
message text
message text
message text

I need to be able to assign a variable to the data like so:

$to = everything to the left of TO;
$subject = everything to the left of SUBJECT;
$message = everything to the left of MESSAGE;

so

$to = name;
$subject = stuff;
$message = message text\nmessage text\nmessage text\n;

This is how it's being done in perl:

open(INPUT, $file) or die couldn't open $file for reading: $!\n;
while (defined (my $line = INPUT)) {
  chomp $line;
  field_found($line,TO,\$to);
  field_found($line,SUBJECT,\$subject);
  field_found($line,MESSAGE,\$message);
}

sub field_found(@_) {
  my $line = shift;
  my $fld  = shift;
  my $val  = shift;

  my $pos = index($line,$fld);
  if ($pos == 0) { # found field
my $flen = length $fld;
my $llen = length $line;
$$val = substr($line,$flen,$llen);
  } # found field
}

How in the world can I translate this to php?

sa

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



RE: [PHP] How do I do this PERL in PHP?

2003-09-16 Thread Susan Ator
It works beautifully. My only question is there a way to pass a variable to
the ereg? In other words:

if( ereg( '^TO(.*)$', $line, $matches ) )

would become:

if( ereg( '^$var(.*)$', $line, $matches ) )

I've tried doing eval but that was a no go.

I have a lot of fields and I hate doing the same thing over and over if
there is a way to avoid it. :)

sa


-Original Message-
From: Robert Cummings [mailto:[EMAIL PROTECTED]
Sent: Tuesday, September 16, 2003 12:05 PM
To: Susan Ator
Cc: [EMAIL PROTECTED]
Subject: Re: [PHP] How do I do this PERL in PHP?


This isn't tested, but should work :)

//

$to = '';
$subject = '';
$message = '';

$matches = array();

$data = file( $file );
foreach( $data as $id = $line )
{
if( ereg( '^TO(.*)$', $line, $matches ) )
{
$to = trim( $matches[1] );
unset( $data[$id] );
}
else
if( ereg( '^FROM(.*)$', $line, $matches ) )
{
$from = trim( $matches[1] );
unset( $data[$id] );
}
}

$message = implode( '', $data );

//

Cheers,
Rob.


On Tue, 2003-09-16 at 11:46, Susan Ator wrote:
 I have a text file with the following format:
 
 TO name
 SUBJECT stuff
 MESSAGE
 message text
 message text
 message text
 
 I need to be able to assign a variable to the data like so:
 
 $to = everything to the left of TO;
 $subject = everything to the left of SUBJECT;
 $message = everything to the left of MESSAGE;
 
 so
 
 $to = name;
 $subject = stuff;
 $message = message text\nmessage text\nmessage text\n;
 
 This is how it's being done in perl:
 
 open(INPUT, $file) or die couldn't open $file for reading: $!\n;
 while (defined (my $line = INPUT)) {
   chomp $line;
   field_found($line,TO,\$to);
   field_found($line,SUBJECT,\$subject);
   field_found($line,MESSAGE,\$message);
 }
 
 sub field_found(@_) {
   my $line = shift;
   my $fld  = shift;
   my $val  = shift;
 
   my $pos = index($line,$fld);
   if ($pos == 0) { # found field
 my $flen = length $fld;
 my $llen = length $line;
 $$val = substr($line,$flen,$llen);
   } # found field
 }
 
 How in the world can I translate this to php?
 
 sa
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 
 
-- 
.-.
| Worlds of Carnage - http://www.wocmud.org   |
:-:
| Come visit a world of myth and legend where |
| fantastical creatures come to life and the  |
| stuff of nightmares grasp for your soul.|
`-'

-- 
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] How do I do this PERL in PHP?

2003-09-16 Thread Susan Ator
Thank y'all so much for all your help.

sa

-Original Message-
From: Robert Cummings [mailto:[EMAIL PROTECTED]
Sent: Tuesday, September 16, 2003 2:30 PM
To: Susan Ator
Cc: [EMAIL PROTECTED]
Subject: RE: [PHP] How do I do this PERL in PHP?


The following will do variable matching like you asked:

if( ereg( '^'.$var.'(.*)$', $line, $matches ) )

Cheers,
Rob.


On Tue, 2003-09-16 at 13:34, Susan Ator wrote:
 It works beautifully. My only question is there a way to pass a variable
to
 the ereg? In other words:
 
 if( ereg( '^TO(.*)$', $line, $matches ) )
 
 would become:
 
 if( ereg( '^$var(.*)$', $line, $matches ) )
 
 I've tried doing eval but that was a no go.
 
 I have a lot of fields and I hate doing the same thing over and over if
 there is a way to avoid it. :)
 
 sa
 
 
 -Original Message-
 From: Robert Cummings [mailto:[EMAIL PROTECTED]
 Sent: Tuesday, September 16, 2003 12:05 PM
 To: Susan Ator
 Cc: [EMAIL PROTECTED]
 Subject: Re: [PHP] How do I do this PERL in PHP?
 
 
 This isn't tested, but should work :)
 
 //
 
 $to = '';
 $subject = '';
 $message = '';
 
 $matches = array();
 
 $data = file( $file );
 foreach( $data as $id = $line )
 {
 if( ereg( '^TO(.*)$', $line, $matches ) )
 {
 $to = trim( $matches[1] );
 unset( $data[$id] );
 }
 else
 if( ereg( '^FROM(.*)$', $line, $matches ) )
 {
 $from = trim( $matches[1] );
 unset( $data[$id] );
 }
 }
 
 $message = implode( '', $data );
 
 //
 
 Cheers,
 Rob.
 
 
 On Tue, 2003-09-16 at 11:46, Susan Ator wrote:
  I have a text file with the following format:
  
  TO name
  SUBJECT stuff
  MESSAGE
  message text
  message text
  message text
  
  I need to be able to assign a variable to the data like so:
  
  $to = everything to the left of TO;
  $subject = everything to the left of SUBJECT;
  $message = everything to the left of MESSAGE;
  
  so
  
  $to = name;
  $subject = stuff;
  $message = message text\nmessage text\nmessage text\n;
  
  This is how it's being done in perl:
  
  open(INPUT, $file) or die couldn't open $file for reading: $!\n;
  while (defined (my $line = INPUT)) {
chomp $line;
field_found($line,TO,\$to);
field_found($line,SUBJECT,\$subject);
field_found($line,MESSAGE,\$message);
  }
  
  sub field_found(@_) {
my $line = shift;
my $fld  = shift;
my $val  = shift;
  
my $pos = index($line,$fld);
if ($pos == 0) { # found field
  my $flen = length $fld;
  my $llen = length $line;
  $$val = substr($line,$flen,$llen);
} # found field
  }
  
  How in the world can I translate this to php?
  
  sa
  
  -- 
  PHP General Mailing List (http://www.php.net/)
  To unsubscribe, visit: http://www.php.net/unsub.php
  
  
 -- 
 .-.
 | Worlds of Carnage - http://www.wocmud.org   |
 :-:
 | Come visit a world of myth and legend where |
 | fantastical creatures come to life and the  |
 | stuff of nightmares grasp for your soul.|
 `-'
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 
-- 
.-.
| Worlds of Carnage - http://www.wocmud.org   |
:-:
| Come visit a world of myth and legend where |
| fantastical creatures come to life and the  |
| stuff of nightmares grasp for your soul.|
`-'

-- 
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