php-general Digest 28 Jul 2006 10:42:17 -0000 Issue 4262

Topics (messages 239839 through 239847):

Re: Problem with rawurlencode and euro sign.
        239839 by: Mathijs van Veluw
        239840 by: Jochem Maas
        239841 by: Satyam

Re: Return Values Copied? Copied if By Reference?
        239842 by: Robert Cummings
        239843 by: Adam Zey
        239844 by: KermodeBear
        239845 by: Adam Zey
        239846 by: Robert Cummings

compare values in 2 array
        239847 by: weetat

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 ---
Thx for that website :).

It helped.
I Think the server i am sending to is on windows, and i changed the encoding to 
windows-1252 and that has it on %80.
Going to contact the company to ask this :).

Thx for the link.


Jochem Maas wrote:
likely to be something to do with the fact that the euro character does not
exist in ISO8859-1.

maybe this page helps:
        http://www.gar.no/html/euro.htm

Mathijs wrote:
Hello there,

I have a problem with rawurlencode().
I want to have the euro sign € to be sent by post.
To do this, first rawurlencode() encodes all the chars.

But for some reason rawurlencode encodes it to %3F or %A4.
Which i think is logical becouse that is the right position in the charset.

But i need it to be %80.

When i use rawurldecode('%80'); and put the browsers encoding to
ISO-8859-* it does work.
i Realy see the euro sign.

So why does rawurlencode() not encodes it tho this?.

Thx in advance.

Mathijs.


---
avast! Antivirus: Outbound message clean.
Virus Database (VPS): 0630-2, 07/26/2006
Tested on: 7/27/2006 12:20:37 PM
avast! - copyright (c) 1988-2006 ALWIL Software.
http://www.avast.com



---
avast! Antivirus: Inbound message clean.
Virus Database (VPS): 0630-2, 07/26/2006
Tested on: 7/27/2006 12:43:09 PM
avast! - copyright (c) 1988-2006 ALWIL Software.
http://www.avast.com






---
avast! Antivirus: Outbound message clean.
Virus Database (VPS): 0630-2, 07/26/2006
Tested on: 7/27/2006 12:50:09 PM
avast! - copyright (c) 1988-2006 ALWIL Software.
http://www.avast.com

--- End Message ---
--- Begin Message ---
likely to be something to do with the fact that the euro character does not
exist in ISO8859-1.

maybe this page helps:
        http://www.gar.no/html/euro.htm

Mathijs wrote:
> Hello there,
> 
> I have a problem with rawurlencode().
> I want to have the euro sign € to be sent by post.
> To do this, first rawurlencode() encodes all the chars.
> 
> But for some reason rawurlencode encodes it to %3F or %A4.
> Which i think is logical becouse that is the right position in the charset.
> 
> But i need it to be %80.
> 
> When i use rawurldecode('%80'); and put the browsers encoding to
> ISO-8859-* it does work.
> i Realy see the euro sign.
> 
> So why does rawurlencode() not encodes it tho this?.
> 
> Thx in advance.
> 
> Mathijs.
> 
> 
> ---
> avast! Antivirus: Outbound message clean.
> Virus Database (VPS): 0630-2, 07/26/2006
> Tested on: 7/27/2006 12:20:37 PM
> avast! - copyright (c) 1988-2006 ALWIL Software.
> http://www.avast.com
> 

--- End Message ---
--- Begin Message ---
At:

http://es2.php.net/manual/en/function.htmlentities.php

it says that ISO-8859-15 adds the Euro sign


----- Original Message ----- From: "Jochem Maas" <[EMAIL PROTECTED]>
To: "Mathijs" <[EMAIL PROTECTED]>
Cc: <[email protected]>
Sent: Thursday, July 27, 2006 12:39 PM
Subject: Re: [PHP] Problem with rawurlencode and euro sign.


likely to be something to do with the fact that the euro character does not
exist in ISO8859-1.

maybe this page helps:
http://www.gar.no/html/euro.htm

Mathijs wrote:
Hello there,

I have a problem with rawurlencode().
I want to have the euro sign € to be sent by post.
To do this, first rawurlencode() encodes all the chars.

But for some reason rawurlencode encodes it to %3F or %A4.
Which i think is logical becouse that is the right position in the charset.

But i need it to be %80.

When i use rawurldecode('%80'); and put the browsers encoding to
ISO-8859-* it does work.
i Realy see the euro sign.

So why does rawurlencode() not encodes it tho this?.

Thx in advance.

Mathijs.


---
avast! Antivirus: Outbound message clean.
Virus Database (VPS): 0630-2, 07/26/2006
Tested on: 7/27/2006 12:20:37 PM
avast! - copyright (c) 1988-2006 ALWIL Software.
http://www.avast.com


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




--- End Message ---
--- Begin Message ---
On Thu, 2006-07-27 at 01:35, Larry Garfield wrote:
> On Wednesday 26 July 2006 21:41, Robert Cummings wrote:
> 
> > > I'm working on some code that would be called to generate a cell in a
> > > possibly large table and therefore a small difference in performance
> > > may have a significant impact.
> >
> > PHP uses copy-on-write and so copies are essentially shared until such
> > time as you modify one of them. If you don't need references then copies
> > are faster than references.
> 
> By the same token, then, if I have a function that generates a large string 
> and returns it, is there any benefit to return-by-reference?

Nope. You should only use references if you really need them. Attempting
to improve efficiency by using references instead of copies when you
aren't actually in need of a reference will result in less efficiency
since the engine spends more time creating the reference than the copy.

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.          |
`------------------------------------------------------------'

--- End Message ---
--- Begin Message ---
Robert Cummings wrote:
On Thu, 2006-07-27 at 01:35, Larry Garfield wrote:
On Wednesday 26 July 2006 21:41, Robert Cummings wrote:

I'm working on some code that would be called to generate a cell in a
possibly large table and therefore a small difference in performance
may have a significant impact.
PHP uses copy-on-write and so copies are essentially shared until such
time as you modify one of them. If you don't need references then copies
are faster than references.
By the same token, then, if I have a function that generates a large string and returns it, is there any benefit to return-by-reference?

Nope. You should only use references if you really need them. Attempting
to improve efficiency by using references instead of copies when you
aren't actually in need of a reference will result in less efficiency
since the engine spends more time creating the reference than the copy.

Cheers,
Rob.

Then how come when I do a foreach on an array (without modifying anything within the foreach), it still makes a copy of the array that consumes memory? I think it's dangerous to generalize that it's always best to let PHP make copies of things. In the foreach situation, the preferred solution when memory is a problem is to either use a reference, or have foreach iterate over the keys of the array.

Regards, Adam.

--- End Message ---
--- Begin Message ---
Robert Cummings wrote:

Then how come when I do a foreach on an array (without modifying 
anything within the foreach), it still makes a copy of the array that 
consumes memory? I think it's dangerous to generalize that it's always 
best to let PHP make copies of things. In the foreach situation, the 
preferred solution when memory is a problem is to either use a 
reference, or have foreach iterate over the keys of the array.

Regards, Adam.

-----

PHP doesn't seem to make a real copy of data until one of the copies is
modified, making it necessary to create a new set of data. So, it is pretty
smart about that.

Here is a small CLI script that seems to support this:
<?php
$a_array = array();
for($i = 0; $i < 10000; $i++) {
        $a_array[] = time(); // Just an arbitrary piece of data
}
echo 'Memory Usage: ' . memory_get_usage() . "\n";
echo "Making a copy of the array.\n";
$a_copy = $a_array;
echo 'Memory Usage: ' . memory_get_usage() . "\n";
echo "Modifying the copy:\n";
$a_copy[] = time();
echo 'Memory Usage: ' . memory_get_usage() . "\n";
?>

On my machine, this displays:
Memory Usage: 640280
Making a copy of the array.
Memory Usage: 640440
Modifying the copy:
Memory Usage: 1106056

-K. Bear

--- End Message ---
--- Begin Message ---
KermodeBear wrote:
Robert Cummings wrote:

Then how come when I do a foreach on an array (without modifying anything within the foreach), it still makes a copy of the array that consumes memory? I think it's dangerous to generalize that it's always best to let PHP make copies of things. In the foreach situation, the preferred solution when memory is a problem is to either use a reference, or have foreach iterate over the keys of the array.

Regards, Adam.

-----

PHP doesn't seem to make a real copy of data until one of the copies is
modified, making it necessary to create a new set of data. So, it is pretty
smart about that.

Here is a small CLI script that seems to support this:
<?php
$a_array = array();
for($i = 0; $i < 10000; $i++) {
        $a_array[] = time(); // Just an arbitrary piece of data
}
echo 'Memory Usage: ' . memory_get_usage() . "\n";
echo "Making a copy of the array.\n";
$a_copy = $a_array;
echo 'Memory Usage: ' . memory_get_usage() . "\n";
echo "Modifying the copy:\n";
$a_copy[] = time();
echo 'Memory Usage: ' . memory_get_usage() . "\n";
?>

On my machine, this displays:
Memory Usage: 640280
Making a copy of the array.
Memory Usage: 640440
Modifying the copy:
Memory Usage: 1106056

-K. Bear

I note that your example doesn't use a foreach loop, which is what my post was about.

Some testing shows my original premise was wrong, but it's still possible to get PHP to copy the array when it doesn't need to. In this case, using a reference can save memory even when a reference isn't needed. If you want to modify the original array in the foreach, then it is better to step over the array yourself and save memory, or pass the foreach a reference to the array to stop it from doing a copy.

I'm just trying to say, I don't think it's always a good idea to rely on the language deciding when to copy. Sometimes it's a good idea to use a reference to stop the copy if memory is a concern.

Regards, Adam Zey.

--- End Message ---
--- Begin Message ---
On Thu, 2006-07-27 at 14:48, Adam Zey wrote:
> KermodeBear wrote:
> > Robert Cummings wrote:
> > 
> > Then how come when I do a foreach on an array (without modifying 
> > anything within the foreach), it still makes a copy of the array that 
> > consumes memory? I think it's dangerous to generalize that it's always 
> > best to let PHP make copies of things. In the foreach situation, the 
> > preferred solution when memory is a problem is to either use a 
> > reference, or have foreach iterate over the keys of the array.
> > 
> > Regards, Adam.
> > 
> > -----
> > 
> > PHP doesn't seem to make a real copy of data until one of the copies is
> > modified, making it necessary to create a new set of data. So, it is pretty
> > smart about that.
> > 
> > Here is a small CLI script that seems to support this:
> > <?php
> > $a_array = array();
> > for($i = 0; $i < 10000; $i++) {
> >         $a_array[] = time(); // Just an arbitrary piece of data
> > }
> > echo 'Memory Usage: ' . memory_get_usage() . "\n";
> > echo "Making a copy of the array.\n";
> > $a_copy = $a_array;
> > echo 'Memory Usage: ' . memory_get_usage() . "\n";
> > echo "Modifying the copy:\n";
> > $a_copy[] = time();
> > echo 'Memory Usage: ' . memory_get_usage() . "\n";
> > ?>
> > 
> > On my machine, this displays:
> > Memory Usage: 640280
> > Making a copy of the array.
> > Memory Usage: 640440
> > Modifying the copy:
> > Memory Usage: 1106056
> > 
> > -K. Bear
> 
> I note that your example doesn't use a foreach loop, which is what my 
> post was about.
> 
> Some testing shows my original premise was wrong, but it's still 
> possible to get PHP to copy the array when it doesn't need to. In this 
> case, using a reference can save memory even when a reference isn't 
> needed. If you want to modify the original array in the foreach, then it 
> is better to step over the array yourself and save memory, or pass the 
> foreach a reference to the array to stop it from doing a copy.
> 
> I'm just trying to say, I don't think it's always a good idea to rely on 
> the language deciding when to copy. Sometimes it's a good idea to use a 
> reference to stop the copy if memory is a concern.

PHP creates a real copy when one of the original arrays changes. This is
the principle of copy-on-write. If you are getting a copy then one of
the arrays changed, so now you really have to choose between a copy and
reference knowing that a reference will affect all arrays to which you
made a reference or a copy which will only affect the copy to which the
change was made. So this returns to my original assertion that you
should only use references when a reference is necessary.

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.          |
`------------------------------------------------------------'

--- End Message ---
--- Begin Message ---
Hi all ,

I am using PHP 4.3.2 and MYSQL DB.

I need to compare values in array which populated by database , below is the code :

$temp_tbl = array();
while ($row = $temptbl_result->fetchRow(DB_FETCHMODE_ASSOC)){
          $rs_chasis_serialno = $row['serial_no'];
          $rs_card_serial_no = $row['card_serial_no'];
          $rs_country = $row['country'];
          $status = $row['status'];
          $temp_tbl[] = array("chassis_serial_no"=>$rs_chasis_serialno,
                              "card_serial_no"=>$rs_card_serial_no,
                              "country"=>country
                              "status"=>status);
}

$current_tbl = array();
while ($row = $currenttbl_result->fetchRow(DB_FETCHMODE_ASSOC)){
          $rs_chasis_serialno = $row['serial_no'];
          $rs_card_serial_no = $row['card_serial_no'];
          $rs_country = $row['country'];
          $current_tbl[] = array("chassis_serial_no"=>$rs_chasis_serialno,
                              "card_serial_no"=>$rs_card_serial_no,
                               "country"=>country);
}

--> need to compare $temp_tbl array and $current_tbl array.
--> if values is different between 2 array , need to update the status field in the $temp_tbl array.

Anybody have any suggestion how to do this ?
Thanks

--- End Message ---

Reply via email to