php-general Digest 3 Aug 2003 13:04:03 -0000 Issue 2214

Topics (messages 158061 through 158072):

Re: Trouble with Session var
        158061 by: Curt Zirzow

Re: subtracting dates...
        158062 by: John Ryan

Re: Pushing array onto array
        158063 by: Curt Zirzow
        158065 by: Hank TT
        158066 by: Jason Wong
        158068 by: Hank TT

Re: preg_match
        158064 by: Lee Doolan
        158067 by: Hank TT
        158069 by: Michael Temeschinko
        158070 by: Michael Temeschinko

PHP SESSIONS and FRAMES
        158071 by: Ralph Guzman

Re: [PHP-DB] subtracting dates...
        158072 by: Matthew McNicol

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 ---
* Thus wrote James Johnson ([EMAIL PROTECTED]):
> Hello,

hello james.

> 
> Is there a limit or something to the number of Session vars that can be
> used? I've even tried setting a Session var called "foo" and that doesn't
> work.

None that php enforces, only the operating system's filesystem and
the sanity of passing around  2MB of session data :)


>       $row_GetCatText= mysql_fetch_assoc($GetCatText);
>       $HTTP_SESSION_VARS['sv_adCatText'] = $row_GetCatText['category'];
>       if($HTTP_SESSION_VARS['sv_adCatText'] == "Books"){
>               header("Location: " . "CreateAdBook.php");
>               exit;
>       }else{
>               header("Location: " . "CreateAdNonBook.php");

These location headers should be using an absolute URI
(http://server/path/to/file.php)

As for your session problem, I'm not entirely sure but one
recommendation would be to ensure that a 'Connection: close' header
is sent to the client also. 


Curt
-- 
"I used to think I was indecisive, but now I'm not so sure."

--- End Message ---
--- Begin Message ---
yeah, thats the code i wrote myself (nearly). it gets the job done.
thanks

"Curt Zirzow" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> * Thus wrote John Ryan ([EMAIL PROTECTED]):
> > Hi,
> >
> hello ryan,
>
> > In mySQL, I store dates as YYYY-MM-DD, a standard DATE type. It stores
users
> > date of births. I need to calculate in a PHP script, the users age from
this
> > DOB. I get a PHP date in the same format as the mySQL and subtract,
which
> > returns the year rounded off. ie, it doesnt matter if your birthdays in
june
> > of 1983 and the date is januray 2003, your age is still returned as 20,
when
> > it should be 19.
> >
> > Does anyone know how can i get the right age?
>
> To get a real age of someone you would use seconds, but since the actual
> count of seconds get messed up on leap years (through the convertion
> from seconds to years),  I approached it with the method most people
> calculate ages.
>
> Most people first look at the year and find the differnce, then if
> the month/day hasn't come around you subtract one; alas the common
> calculation for age.
>
> Here is the code to demonstrate that logic:
>
>
> $dob = split('-', '1980-12-1');
> $now = split('-', date('Y-m-d'));
>
> // we are either this age or one less
> $age = $now[0] - $dob[0];
>
> // have we gotten to the month of in dob?
> if ($now[1] < $dob[1]) {
>
>    // no, so we are technically a year less.
>    $age--;
>
> // If we're in the month,  has the day come yet?
> } elseif ($now[1] = $dob[1] && $now[2] < $now[3]) {
>
>    // no, still a few more days.
>    $age--;
> }
>
> // your age is proper, in day to day usage.
>
> /*
>   Note:
>
>   instead of the if () elseif() you can use
>   if (mktime(0,0,0,$now[1],$now[2]) < mktime(0,0,0,$dob[1],$dob[2])) {
>     $age--;
>   }
>
> */
>
>
> HTH,
>
> Curt
> --
> "I used to think I was indecisive, but now I'm not so sure."



--- End Message ---
--- Begin Message ---
* Thus wrote Andrew Brampton ([EMAIL PROTECTED]):
> No there is a difference...
> 
> Take the example
> [ [a, b, c] , [ d, e, f] ]
> In a 2 dimensional array those values would be stored adjacent in memory...
> ie
> a b c d e f
> 
> In a Array of Arrays, the first and 2nd elements would be pointers, to where
> the [a, b, c], and [d, e, f] arrays are actually kept... ie
> 0 1 2 3 4 5 6 7
> 2 3 a b c d e f
> but this can all depend on the compiler, and the language construct... But
> its best to recognise a difference even if its really small...

how they are aligned in memory doesn't make them different in what
they are. Either way you still have a 2 dimential matrix.

> 
> and in PHP it can get even more confusing with its non strict typing, and
> un-fixed size arrays etc...

Some would argue this. PHP makes it easier for the programmer, so
he doesn't have to worry about type differences, memory allocation
and lower level access.  The programmer just needs to assign a
variable and poof... it is created.

> 
> Andrew
> ----- Original Message -----
> From: "Curt Zirzow" <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Saturday, August 02, 2003 11:06 PM
> Subject: Re: [PHP] Pushing array onto array
> 
> 
> > * Thus wrote Andrew Brampton ([EMAIL PROTECTED]):
> > >
> > > It works exactly how it should... However really the array isn't a 2
> > > dimensional one, since PHP doesn't have them, its rather a array of
> arrays
> > > which is roughly the same thing (and something not to worry about)...
> >
> > A 2 demensional array is an array of arrays.


Curt
-- 
"I used to think I was indecisive, but now I'm not so sure."

--- End Message ---
--- Begin Message ---
Well, I might have been more specific about their example, since not
everyone has the book.  An excerpt below (so I don't need to retype all the
names of characters and foul creatures from the Lord of the Rings):

---------------------------
$arr1 = array('G', 'R', 'Sr');
$arr2 = array('N', 'Su', 'O');

$arr3 = array_push($arr1, $arr2);

print $arr3[3][1];
//prints Su
---------------------------

Weird usage....







----- Original Message -----
From: "Andrew Brampton" <[EMAIL PROTECTED]>
To: "Hank TT" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>
Sent: Saturday, August 02, 2003 2:09 PM
Subject: Re: [PHP] Pushing array onto array


> Well I just coded up a very small example, and it pushing 1 array into the
> other...
>
> Check out: http://81.102.229.151/push.php and
> http://81.102.229.151/push.phps
>
> It works exactly how it should... However really the array isn't a 2
> dimensional one, since PHP doesn't have them, its rather a array of arrays
> which is roughly the same thing (and something not to worry about)...
>
> If you need more help just email me
> Andrew








--- End Message ---
--- Begin Message ---
On Sunday 03 August 2003 13:02, Hank TT wrote:
> Well, I might have been more specific about their example, since not
> everyone has the book.  An excerpt below (so I don't need to retype all the
> names of characters and foul creatures from the Lord of the Rings):
>
> ---------------------------
> $arr1 = array('G', 'R', 'Sr');
> $arr2 = array('N', 'Su', 'O');
>
> $arr3 = array_push($arr1, $arr2);
>
> print $arr3[3][1];
> //prints Su
> ---------------------------

I don't see how your example could work. array_push() does NOT return an 
array. The results of array_push() is placed in the first argument -- in this 
case $arr1.

> Weird usage....

Think of it like this -- it adds the 2nd array onto the 1st array.

It does NOT add the *contents* of the 2nd array to the 1st array -- for that 
you would probably use array_merge().

Do a print_r($arr1), it might help you visualise what happens.

-- 
Jason Wong -> Gremlins Associates -> www.gremlins.biz
Open Source Software Systems Integrators
* Web Design & Hosting * Internet & Intranet Applications Development *
------------------------------------------
Search the list archives before you post
http://marc.theaimsgroup.com/?l=php-general
------------------------------------------
/*
It is now pitch dark.  If you proceed, you will likely fall into a pit.
*/


--- End Message ---
--- Begin Message ---
James,

My question had more to do with why the authors would give this usage when
array_push is not documented to behave so (as you correctly described).
Were they describing an earlier version of array_push?  A simple buggy
example?  A typo perhaps?

Since the authors Hughes and Zmievski are big names in PHP, though mortals
like you and me, I'm inclined to think they were thinking about something.




----- Original Message -----
From: "Jason Wong" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Sunday, August 03, 2003 1:27 AM
Subject: Re: [PHP] Pushing array onto array


> On Sunday 03 August 2003 13:02, Hank TT wrote:
> > Well, I might have been more specific about their example, since not
> > everyone has the book.  An excerpt below (so I don't need to retype all
the
> > names of characters and foul creatures from the Lord of the Rings):
> >
> > ---------------------------
> > $arr1 = array('G', 'R', 'Sr');
> > $arr2 = array('N', 'Su', 'O');
> >
> > $arr3 = array_push($arr1, $arr2);
> >
> > print $arr3[3][1];
> > //prints Su
> > ---------------------------
>
> I don't see how your example could work. array_push() does NOT return an
> array. The results of array_push() is placed in the first argument -- in
this
> case $arr1.
>
> > Weird usage....
>
> Think of it like this -- it adds the 2nd array onto the 1st array.
>
> It does NOT add the *contents* of the 2nd array to the 1st array -- for
that
> you would probably use array_merge().
>
> Do a print_r($arr1), it might help you visualise what happens.
>
> --
> Jason Wong -> Gremlins Associates -> www.gremlins.biz
> Open Source Software Systems Integrators
> * Web Design & Hosting * Internet & Intranet Applications Development *
> ------------------------------------------
> Search the list archives before you post
> http://marc.theaimsgroup.com/?l=php-general
> ------------------------------------------
> /*
> It is now pitch dark.  If you proceed, you will likely fall into a pit.
> */
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>






--- End Message ---
--- Begin Message ---
>>>>> "Michael" == Michael Temeschinko <[EMAIL PROTECTED]> writes:

    Michael> Hello,
    Michael> I would like to split a String containing ingredience with additional
    Michael> assigned footnotes...

    Michael> my problem I only get the first ingredience ($zutat at line 32 has
    Michael> only one times the awaited value) but the print on line 29 shows me
    Michael> that the value of $zutat is right at this point.

    Michael> what's wrong ????

    Michael>        1 <?php
    Michael>        2
    Michael>        3 $products_ingredience = 'Gersten-Grütze²*, Gerstenmehl²*,
    Michael> Haferflocken*, Gemüse 12 % (Lauch*, Möhren*, Zwiebeln*), Haferkleie*,
    Michael> Steinsalz, Petersilie*, Kartoffelstärke*, Hefeextrakt, Sellerieblatt*,
    Michael> Kurkuma*, Muskatnuß*, Pfeffer*, Liebstöckl*';
    Michael>        4
    Michael>        5 ArtikelZutaten ($products_ingredience);
    Michael>        6
    Michael>        7
    Michael>        8 function ArtikelZutaten($products_ingredience) {
    Michael>        9
    Michael>       10
    Michael>       11 print "\n\n\n$products_ingredience)";
    Michael>       12         $Zutaten = explode(",", $products_ingredience);
    Michael>       13
    Michael>       14         foreach ($Zutaten as $zutat) {
    Michael>       15                 if (preg_match("/\²/", $zutat))
    Michael>       16                         $FussnoteID = 2;
    Michael>       17                 else
    Michael>       18                         $FussnoteID = '';
    Michael>       19
    Michael>       20                 if (preg_match("/¹/", $zutat))
    Michael>       21                         $FussnoteID = 1;
    Michael>       22
    Michael>       23                 if (preg_match("/\*/", $zutat))
    Michael>       24                         $kbA = 1;
    Michael>       25                 else
    Michael>       26                         $kbA = 0;
    Michael>       27
    Michael>       28                 preg_match("/\b.*\b/", $zutat, $matches);
    Michael>       29 print "\n-->>$zutat";
    Michael>       30                 $zutat = $matches[0];
    Michael>       31
    Michael>       32 print "\nZutat $zutat FussnotenID $FussnoteID kbA $kbA";
    Michael>       33
    Michael>       34         }
    Michael>       35
    Michael>       36 }
    Michael>       37
    Michael>       38 ?>

what do you get if you 
      print "\nmatches matches..."; var_dump($matches);

right after line 32?

-- 
no toll on the internet; there are paths of many kinds;
whoever passes this portal will travel freely in the world

--- End Message ---
--- Begin Message ---
Either of these should work:

preg_match("/\b.*\b/", trim($zutat), $matches);
preg_match("/\b.+\b/", $zutat, $matches);

I'll leave the why to someone else :)


----- Original Message -----
From: "Michael Temeschinko" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Saturday, August 02, 2003 7:55 PM
Subject: [PHP] preg_match


> Hello,
>
> I would like to split a String containing ingredience with additional
> assigned footnotes...
>
> my problem I only get the first ingredience ($zutat at line 32 has only
> one times the awaited value) but the print on line 29 shows me that the
> value of $zutat is right at this point.
>
> what's wrong ????
>
>        1 <?php
>        2
>        3 $products_ingredience = 'Gersten-Grütze²*, Gerstenmehl²*,
> Haferflocken*, Gemüse 12 % (Lauch*, Möhren*, Zwiebeln*), Haferkleie*,
> Steinsalz, Petersilie*, Kartoffelstärke*, Hefeextrakt, Sellerieblatt*,
> Kurkuma*, Muskatnuß*, Pfeffer*, Liebstöckl*';
>        4
>        5 ArtikelZutaten ($products_ingredience);
>        6
>        7
>        8 function ArtikelZutaten($products_ingredience) {
>        9
>       10
>       11 print "\n\n\n$products_ingredience)";
>       12         $Zutaten = explode(",", $products_ingredience);
>       13
>       14         foreach ($Zutaten as $zutat) {
>       15                 if (preg_match("/\²/", $zutat))
>       16                         $FussnoteID = 2;
>       17                 else
>       18                         $FussnoteID = '';
>       19
>       20                 if (preg_match("/¹/", $zutat))
>       21                         $FussnoteID = 1;
>       22
>       23                 if (preg_match("/\*/", $zutat))
>       24                         $kbA = 1;
>       25                 else
>       26                         $kbA = 0;
>       27
>       28                 preg_match("/\b.*\b/", $zutat, $matches);
>       29 print "\n-->>$zutat";
>       30                 $zutat = $matches[0];
>       31
>       32 print "\nZutat $zutat FussnotenID $FussnoteID kbA $kbA";
>       33
>       34         }
>       35
>       36 }
>       37
>       38 ?>
>
>
>
> mfg - micha
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>



--- End Message ---
--- Begin Message --- Lee Doolan wrote:
"Michael" == Michael Temeschinko <[EMAIL PROTECTED]> writes:


    Michael> Hello,
    Michael> I would like to split a String containing ingredience with additional
    Michael> assigned footnotes...

    Michael> my problem I only get the first ingredience ($zutat at line 32 has
    Michael> only one times the awaited value) but the print on line 29 shows me
    Michael> that the value of $zutat is right at this point.

Michael> what's wrong ????

    Michael>        1 <?php
    Michael>        2
    Michael>        3 $products_ingredience = 'Gersten-Grütze²*, Gerstenmehl²*,
    Michael> Haferflocken*, Gemüse 12 % (Lauch*, Möhren*, Zwiebeln*), Haferkleie*,
    Michael> Steinsalz, Petersilie*, Kartoffelstärke*, Hefeextrakt, Sellerieblatt*,
    Michael> Kurkuma*, Muskatnuß*, Pfeffer*, Liebstöckl*';
    Michael>        4
    Michael>        5 ArtikelZutaten ($products_ingredience);
    Michael>        6
    Michael>        7
    Michael>        8 function ArtikelZutaten($products_ingredience) {
    Michael>        9
    Michael>       10
    Michael>       11 print "\n\n\n$products_ingredience)";
    Michael>       12         $Zutaten = explode(",", $products_ingredience);
    Michael>       13
    Michael>       14         foreach ($Zutaten as $zutat) {
    Michael>       15                 if (preg_match("/\²/", $zutat))
    Michael>       16                         $FussnoteID = 2;
    Michael>       17                 else
    Michael>       18                         $FussnoteID = '';
    Michael>       19
    Michael>       20                 if (preg_match("/¹/", $zutat))
    Michael>       21                         $FussnoteID = 1;
    Michael>       22
    Michael>       23                 if (preg_match("/\*/", $zutat))
    Michael>       24                         $kbA = 1;
    Michael>       25                 else
    Michael>       26                         $kbA = 0;
    Michael>       27
    Michael>       28                 preg_match("/\b.*\b/", $zutat, $matches);
    Michael>       29 print "\n-->>$zutat";
    Michael>       30                 $zutat = $matches[0];
    Michael>       31
    Michael>       32 print "\nZutat $zutat FussnotenID $FussnoteID kbA $kbA";
    Michael>       33
    Michael>       34         }
    Michael>       35
    Michael>       36 }
    Michael>       37
    Michael>       38 ?>

what do you get if you print "\nmatches matches..."; var_dump($matches);

right after line 32?


Hi Lee,


additionaly I have switched the warnings on:

Gersten-Grütze²*, Gerstenmehl²*, Haferflocken*, Gemüse 12 % (Lauch*, Möhren*, Zwiebeln*), Haferkleie*, Steinsalz, Petersilie*, Kartoffelstärke*, Hefeextrakt, Sellerieblatt*, Kurkuma*, Muskatnuß*, Pfeffer*, Liebstöckl*)
-->>Gersten-Grütze²*
Zutat Gersten-Grütze FussnotenID 2 kbA 1
matches matches...array(1) {
[0]=>
string(14) "Gersten-Grütze"
}


-->> Gerstenmehl²*
Notice: Undefined offset:  0 in /home/mt/amorebio/dem1.php on line 30

Zutat  FussnotenID 2 kbA 1
matches matches...array(0) {
}

-->> Haferflocken*
Notice: Undefined offset:  0 in /home/mt/amorebio/dem1.php on line 30

Zutat  FussnotenID  kbA 1
matches matches...array(0) {
}



.... and so on

why does he matches only the first time ??

Greetings from Germany
Micha


--- End Message ---
--- Begin Message --- Hank Tt wrote:
Either of these should work:

preg_match("/\b.*\b/", trim($zutat), $matches);

Thank you - that's the solution :-)


mfg - micha


--- End Message ---
--- Begin Message ---
I have a shopping cart with affiliate sales support. What's happening is
that some affiliates are using frames to use their domain while using
our shopping cart. So they are using a frameset like this:

<frameset rows="1,*" FRAMEBORDER=0 BORDER=0>

   <frame MARGINWIDTH="0" MARGINHEIGHT="0" 
   name="board" src="top.html">

   <frame MARGINWIDTH="0" MARGINHEIGHT="0" 
   name="post" src="http://www.domain.com/?store_id=15008";>

</frameset>

The problem I'm having is that sessions are not being passed properly or
are expiring. 

Anybody experience this kind of problem? If so can you provide any
advice on passing sessions through frames?

Thanks.




--- End Message ---
--- Begin Message ---
> In mySQL, I store dates as YYYY-MM-DD, a standard DATE type. It stores
users
> date of births. I need to calculate in a PHP script, the users age from
this
> DOB. I get a PHP date in the same format as the mySQL and subtract, which
> returns the year rounded off. ie, it doesnt matter if your birthdays in
june
> of 1983 and the date is januray 2003, your age is still returned as 20,
when
> it should be 19.
>
> Does anyone know how can i get the right age?


Okay, so you just want to know the age in years. Must you use php? Here is a
solution using mysql :

SELECT name, dob, CURDATE() as today,
( YEAR(CURDATE()) - YEAR(dob) ) +
LEAST( SIGN( DAYOFYEAR(CURDATE()) - DAYOFYEAR(dob) ), 0) as age_in_years
FROM test_age;

Here is the output :

+------+------------+------------+--------------+
| name | dob        | today      | age_in_years |
+------+------------+------------+--------------+
| jim  | 1990-08-02 | 2003-08-03 |           13 |
| paul | 1990-08-03 | 2003-08-03 |           13 |
| tom  | 1990-08-04 | 2003-08-03 |           12 |
| matt | 1990-09-01 | 2003-08-03 |           12 |
| sam  | 1990-12-31 | 2003-08-03 |           12 |
| sam  | 1991-01-01 | 2003-08-03 |           12 |
| sam  | 1991-07-02 | 2003-08-03 |           12 |
| sam  | 1991-08-02 | 2003-08-03 |           12 |
| sam  | 1991-09-02 | 2003-08-03 |           11 |
+------+------------+------------+--------------+
9 rows in set (0.01 sec)

Here is how I generated my test data :

DROP TABLE IF EXISTS test_age;
CREATE TABLE test_age (
  id int(6) NOT NULL auto_increment,
  name varchar(20) default NULL,
  dob date default NULL,
  PRIMARY KEY  (id)
) TYPE=MyISAM;

INSERT INTO test_age (id, name, dob) VALUES ('', 'jim', '1990-08-02');
INSERT INTO test_age (id, name, dob) VALUES ('', 'paul', '1990-08-03');
INSERT INTO test_age (id, name, dob) VALUES ('', 'tom', '1990-08-04');
INSERT INTO test_age (id, name, dob) VALUES ('', 'matt', '1990-09-01');
INSERT INTO test_age (id, name, dob) VALUES ('', 'sam', '1990-12-31');
INSERT INTO test_age (id, name, dob) VALUES ('', 'sam', '1991-01-01');
INSERT INTO test_age (id, name, dob) VALUES ('', 'sam', '1991-07-02');
INSERT INTO test_age (id, name, dob) VALUES ('', 'sam', '1991-08-02');
INSERT INTO test_age (id, name, dob) VALUES ('', 'sam', '1991-09-02');



> -----Original Message-----
> From: John Ryan [mailto:[EMAIL PROTECTED]
> Sent: Saturday, August 02, 2003 2:31 PM
> To: [EMAIL PROTECTED]; [EMAIL PROTECTED]
> Subject: [PHP-DB] subtracting dates...
>
>
> Hi,
>
> In mySQL, I store dates as YYYY-MM-DD, a standard DATE type. It stores
> users date of births. I need to calculate in a PHP script, the users age
> from this DOB. I get a PHP date in the same format as the mySQL and
> subtract, which returns the year rounded off. ie, it doesnt matter if
> your birthdays in june of 1983 and the date is januray 2003, your age is
> still returned as 20, when it should be 19.
>
> Does anyone know how can i get the right age?
>
>
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.506 / Virus Database: 303 - Release Date: 01/08/2003


--- End Message ---

Reply via email to