OSEC

Neohapsis is currently accepting applications for employment. For more information, please visit our website www.neohapsis.com or email hr@neohapsis.com
 
php-general Digest 13 Jun 2006 16:00:16 -0000 Issue 4183

php-general-digest-helplists.php.net
Date: Tue Jun 13 2006 - 11:00:16 CDT


php-general Digest 13 Jun 2006 16:00:16 -0000 Issue 4183

Topics (messages 237866 through 237908):

Re: Introductory message
        237866 by: Ligaya Turmelle

Re: How to re-order an array
        237867 by: Paul Novitski
        237880 by: tedd

Dettach problem
        237868 by: grape

Help with some clever bit operations
        237869 by: Niels
        237870 by: Barry
        237872 by: David Tulloh
        237873 by: Jochem Maas
        237875 by: Jochem Maas
        237876 by: Ford, Mike
        237877 by: Niels
        237878 by: Niels
        237879 by: Niels
        237882 by: Satyam
        237897 by: Robert Cummings
        237899 by: Jochem Maas
        237901 by: Robert Cummings
        237903 by: Jochem Maas

$B$^$$3$s$J$K%-%l%$(B
        237871 by: eriko

Seeking recommendations for use of include()
        237874 by: Dave M G
        237885 by: tedd
        237887 by: Andrei

GetText string not found
        237881 by: Ruben Rubio Rey
        237884 by: Jochem Maas

Setting headers for file download
        237883 by: Peter Lauri

Re: php->html "rendering"
        237886 by: Ryan A
        237893 by: Larry Garfield

Please help me with a query
        237888 by: Jesús Alain Rodríguez Santos
        237890 by: Jochem Maas
        237892 by: Jef Sullivan

SimpleXMLElement writing problem while in a reference
        237889 by: defragger.arcor.de

Sending UTF-8 mail with mail()
        237891 by: Peter Lauri
        237895 by: Barry
        237904 by: Peter Lauri
        237908 by: tedd

Re: trapping fatal errors...?
        237894 by: Christopher J. Bottaro
        237902 by: Eric Butera
        237905 by: Jochem Maas
        237907 by: Christopher J. Bottaro

URL Rewrite???
        237896 by: Keith
        237900 by: Jochem Maas

Re: date_sunrise accuracy
        237898 by: Jochem Maas

Re: GD
        237906 by: Tom Ray [Lists]

Administrivia:

To subscribe to the digest, e-mail:
        php-general-digest-subscribelists.php.net

To unsubscribe from the digest, e-mail:
        php-general-digest-unsubscribelists.php.net

To post to the list, e-mail:
        php-generallists.php.net

----------------------------------------------------------------------

attached mail follows:


Jay Blanchard wrote:
> [snip]
>
>>Thought we were going to add the "Security" subsection to the "Where
>>to
>>Find More Information" section of the NEWBIE email. Wasn't it
>>supposed
>>to include a link to the manuals security area as well as the phpsec
>>site?
>
>
> +1
> [/snip]
>
> Send me the details and I'll make sure that they get added.
>
>
>
>
<snip from NEWBIE guide>
Where to Find More Information
===============================

If you have any queries/problems about PHP, the online manual (you can get
an offline copy as well) is a good tool to become familiar with.

    http://php.net/manual

  Some Key sections of the PHP Manual:

    - Installation and Configuration
      http://php.net/install

    - Language Reference
      http://php.net/langref

    - Function Reference
      http://php.net/funcref

      tip: if you know the function name but forget exactly how
      it works just type the name of the function ie:
        http://php.net/array_merge

    - The PHP FAQ
      http://php.net/faq
</snip>
+ - Security
+ http://www.php.net/manual/en/security.php
+ Additional PHP Security References:
+ http://phpsec.org/
+ http://www.hardened-php.net/advisories.15.html

--

life is a game... so have fun.

attached mail follows:


At 07:53 PM 6/11/2006, jekillen wrote:
>I force the user to have javascript enabled

Oops.

Unless you're working IT in a penal colony, I suspect that what you
really mean is that you choose to serve broken pages or no content at
all to users who don't have JavaScript enabled, whether by choice or
network requirement or software availability.

It's an interesting decision, excluding browsers with JavaScript
turned off. I can see making it in cases of specialty audiences,
such as the aforementioned penal colony, customized intranets, and
others where all of the user agents are not only predictable but
legislatable. For public websites, I feel we need to set barriers to
entrance only when necessary -- and when is that? -- consciously and
deliberately, focusing not so much on "Look at the cool things we can
do with JavaScript!" but "Whom shall we exclude from this
site?" Look a user in the eye, say, "You can't come in," and reflect
on how cool that is.

Although I still love to write client-side script, most of the energy
I used to expend on JavaScript I now devote to PHP. The server is
the great leveler of the playing field, rendering our pages
accessible to all user agents *if* our designs are sufficiently
clever. These days I mostly add JavaScript to perform functions that
are already performed server-side by PHP, purely for the advantage of
speed, but my best pages perform perfectly with JavaScript turned off.

Aside, the whole client-side/server-side debate depends on today's
internet connection response time being as slow as it is. In a few
years a seemingly sexy technology like Ajax, which appears useful
today in pages so heavy with content that whole-page reloads seem
onerous, will be one of the unbelievable jokes of yesteryear, like
RAM measured in kilobytes, 8" floppy discs, and punch cards.

Regards,
Paul

attached mail follows:


At 11:26 PM -0700 6/12/06, Paul Novitski wrote:
>Aside, the whole client-side/server-side debate depends on today's internet connection response time being as slow as it is. In a few years a seemingly sexy technology like Ajax, which appears useful today in pages so heavy with content that whole-page reloads seem onerous, will be one of the unbelievable jokes of yesteryear, like RAM measured in kilobytes, 8" floppy discs, and punch cards.

Now, there's the way to think !

Don't confine yourself to the limitations of today, but rather open to the expectations of tomorrow.

tedd
--
------------------------------------------------------------------------------------
http://sperling.com http://ancientstones.com http://earthstones.com

attached mail follows:


Hi all,

I would like run a php-script via CLI which outputs some information to
stdout, and then go into background. I use code similar to this to fork
and to dettach the child I/O from the TTY (some error handling removed
to improve readability)

<?
echo "Hello from parent\n";

if(pcntl_fork()) {
   exit;
}

posix_setsid();

fclose( STDIN );
fclose( STDOUT );
fclose( STDERR );

if(pcntl_fork()) {
   exit;
}

echo "This message should NOT go to stdout of parent process\n";
?>

It works fine using PHP version 5.0.4, but when using PHP version 5.1.2
the output of the child ("This message....") goes to stdout of the
parent process. So if I do:

php test.php >output

Using PHP 5.1.2, the file contains:

---------------
Hello from parent
This message should NOT go to stdout of parent process
---------------

Can anybody explain this?
I run FreeBSD 6.0-RELEASE...

Regards,

Grape

attached mail follows:


Hi,

I have a problem I can solve with some loops and if-thens, but I'm sure it
can be done with bit operations -- that would be prettier. I've tried to
work it out on paper, but I keep missing the final solution. Maybe I'm
missing something obvious...

The problem: A function tries to update an existing value, but is only
allowed to write certain bits.

There are 3 variables:
A: the existing value, eg. 10110101
B: what the function wants to write, eg. 01011100
C: which bits the function is allowed to write, eg. 00001111

With these examples, 10111100 should be written.

How do I combine A, B and C to get that result?

Thanks,
Niels

attached mail follows:


Niels schrieb:
> Hi,
>
> I have a problem I can solve with some loops and if-thens, but I'm sure it
> can be done with bit operations -- that would be prettier. I've tried to
> work it out on paper, but I keep missing the final solution. Maybe I'm
> missing something obvious...
>
> The problem: A function tries to update an existing value, but is only
> allowed to write certain bits.
>
> There are 3 variables:
> A: the existing value, eg. 10110101
> B: what the function wants to write, eg. 01011100
> C: which bits the function is allowed to write, eg. 00001111
>
> With these examples, 10111100 should be written.
>
> How do I combine A, B and C to get that result?
>
addition probably?

Btw. the result of the addition would be : 111010101

Barry

--
Smileys rule (cX.x)C --o(^_^o)
Dance for me! ^(^_^)o (o^_^)o o(^_^)^ o(^_^o)

attached mail follows:


The example starting values
$existing = 181; # = 10110101
$new = 92; # = 01011100
$mask = 15; # = 00001111

Get the bits that will be changed
$changing = $new & $mask; # = 12 = 00001100

Get the bits that won't be changed
$staying = $existing & ~$mask; # = 176 = 10110000

Combine them together
$result = $changing ^ $staying; # = 188 = 10111100

David

Niels wrote:
> Hi,
>
> I have a problem I can solve with some loops and if-thens, but I'm sure it
> can be done with bit operations -- that would be prettier. I've tried to
> work it out on paper, but I keep missing the final solution. Maybe I'm
> missing something obvious...
>
> The problem: A function tries to update an existing value, but is only
> allowed to write certain bits.
>
> There are 3 variables:
> A: the existing value, eg. 10110101
> B: what the function wants to write, eg. 01011100
> C: which bits the function is allowed to write, eg. 00001111
>
> With these examples, 10111100 should be written.
>
> How do I combine A, B and C to get that result?
>
>
> Thanks,
> Niels
>

attached mail follows:


Niels wrote:
> Hi,
>
> I have a problem I can solve with some loops and if-thens, but I'm sure it
> can be done with bit operations -- that would be prettier. I've tried to
> work it out on paper, but I keep missing the final solution. Maybe I'm
> missing something obvious...
>
> The problem: A function tries to update an existing value, but is only
> allowed to write certain bits.
>
> There are 3 variables:
> A: the existing value, eg. 10110101
> B: what the function wants to write, eg. 01011100
> C: which bits the function is allowed to write, eg. 00001111
>
> With these examples, 10111100 should be written.

My brain needs a crutch when trying doing this kind of thing
(normally I only write hex number literally when dealing with bitwise stuff -
the conversion stuff still makes my head spin) - this is what this table is for:

128 64 32 16 8 4 2 1
1 0 1 1 0 1 0 1
0 1 0 1 1 1 0 0
0 0 0 0 1 1 1 1

and then I did this - hopefully it shows what you can/have to do:

<?php

// set some values
$oldval = 128 + 32 + 16 + 4 + 1; // 10110101
$update = 64 + 16 + 8 + 4; // 01011100
$mask = 8 + 4 + 2 + 1; // 00001111

// do a 'bit' of surgery ...
$add = $mask & $update;
$keep = ~$mask & $oldval;
$newval = $keep | $add;

// show what happened
var_dump(
        str_pad(base_convert($oldval, 10, 2), 8, "0"),
        str_pad(base_convert($update, 10, 2), 8, "0"),
        str_pad(base_convert($mask, 10, 2), 8, "0"),
        str_pad(base_convert($add, 10, 2), 8, "0"),
        str_pad(base_convert($keep, 10, 2), 8, "0"),
        str_pad(base_convert($newval, 10, 2), 8, "0")
);

?>

>
> How do I combine A, B and C to get that result?
>
>
> Thanks,
> Niels
>

attached mail follows:


David Tulloh wrote:
> The example starting values
> $existing = 181; # = 10110101
> $new = 92; # = 01011100
> $mask = 15; # = 00001111
>
> Get the bits that will be changed
> $changing = $new & $mask; # = 12 = 00001100
>
> Get the bits that won't be changed
> $staying = $existing & ~$mask; # = 176 = 10110000
>
> Combine them together
> $result = $changing ^ $staying; # = 188 = 10111100

heck, Davids 'result' line is more correct than mine I believe -
he uses an XOR operation where I used an OR operation - both have the same
result because the set of bits that are 'on' in the first operand are mutually
exclusive to the set of bits that are 'on' in the second operand.

>
>
> David
>
> Niels wrote:
>> Hi,
>>
>> I have a problem I can solve with some loops and if-thens, but I'm sure it
>> can be done with bit operations -- that would be prettier. I've tried to
>> work it out on paper, but I keep missing the final solution. Maybe I'm
>> missing something obvious...
>>
>> The problem: A function tries to update an existing value, but is only
>> allowed to write certain bits.
>>
>> There are 3 variables:
>> A: the existing value, eg. 10110101
>> B: what the function wants to write, eg. 01011100
>> C: which bits the function is allowed to write, eg. 00001111
>>
>> With these examples, 10111100 should be written.
>>
>> How do I combine A, B and C to get that result?
>>
>>
>> Thanks,
>> Niels
>>
>

attached mail follows:


On 13 June 2006 10:31, Niels wrote:

> Hi,
>
> I have a problem I can solve with some loops and if-thens,
> but I'm sure it
> can be done with bit operations -- that would be prettier.
> I've tried to
> work it out on paper, but I keep missing the final solution. Maybe
> I'm missing something obvious...
>
> The problem: A function tries to update an existing value, but is only
> allowed to write certain bits.
>
> There are 3 variables:
> A: the existing value, eg. 10110101
> B: what the function wants to write, eg. 01011100
> C: which bits the function is allowed to write, eg. 00001111
>
> With these examples, 10111100 should be written.
>
> How do I combine A, B and C to get that result?

First use & (bitwise-and) to mask out bits the function is not allowed to write:

    $b & $c // result is 00001100 given above inputs

Then mask the bits that the function will write out of the original value - negate the mask and use & again:

    $a & ~$c // result is 10110000

Then combine the two using | (bitwise-or):

    ($a & ~$c) | ($b & $c) // result is 10111101

Cheers!

Mike

---------------------------------------------------------------------
Mike Ford, Electronic Information Services Adviser,
Learning Support Services, Learning & Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Headingley Campus, LEEDS, LS6 3QS, United Kingdom
Email: m.fordleedsmet.ac.uk
Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211

To view the terms under which this email is distributed, please go to http://disclaimer.leedsmet.ac.uk/email.htm

attached mail follows:


On Tuesday 13 June 2006 12:32, Ford, Mike wrote:

> On 13 June 2006 10:31, Niels wrote:
>
>> Hi,
>>
>> I have a problem I can solve with some loops and if-thens,
>> but I'm sure it
>> can be done with bit operations -- that would be prettier.
>> I've tried to
>> work it out on paper, but I keep missing the final solution. Maybe
>> I'm missing something obvious...
>>
>> The problem: A function tries to update an existing value, but is only
>> allowed to write certain bits.
>>
>> There are 3 variables:
>> A: the existing value, eg. 10110101
>> B: what the function wants to write, eg. 01011100
>> C: which bits the function is allowed to write, eg. 00001111
>>
>> With these examples, 10111100 should be written.
>>
>> How do I combine A, B and C to get that result?
>
> First use & (bitwise-and) to mask out bits the function is not allowed to
> write:
>
> $b & $c // result is 00001100 given above inputs
>
> Then mask the bits that the function will write out of the original value
> - negate the mask and use & again:
>
> $a & ~$c // result is 10110000
>
> Then combine the two using | (bitwise-or):
>
> ($a & ~$c) | ($b & $c) // result is 10111101
 [snip]

Thanks! I appreciate your effort!

Regards,
Niels

attached mail follows:


On Tuesday 13 June 2006 12:22, Jochem Maas wrote:

> Niels wrote:
>> Hi,
>>
>> I have a problem I can solve with some loops and if-thens, but I'm sure
>> it can be done with bit operations -- that would be prettier. I've tried
>> to work it out on paper, but I keep missing the final solution. Maybe I'm
>> missing something obvious...
>>
>> The problem: A function tries to update an existing value, but is only
>> allowed to write certain bits.
>>
>> There are 3 variables:
>> A: the existing value, eg. 10110101
>> B: what the function wants to write, eg. 01011100
>> C: which bits the function is allowed to write, eg. 00001111
>>
>> With these examples, 10111100 should be written.
>
> My brain needs a crutch when trying doing this kind of thing
> (normally I only write hex number literally when dealing with bitwise
> stuff - the conversion stuff still makes my head spin) - this is what this
> table is for:
>
> 128 64 32 16 8 4 2 1
> 1 0 1 1 0 1 0 1
> 0 1 0 1 1 1 0 0
> 0 0 0 0 1 1 1 1
>
> and then I did this - hopefully it shows what you can/have to do:
>
> <?php
>
> // set some values
> $oldval = 128 + 32 + 16 + 4 + 1; // 10110101
> $update = 64 + 16 + 8 + 4; // 01011100
> $mask = 8 + 4 + 2 + 1; // 00001111
>
> // do a 'bit' of surgery ...
> $add = $mask & $update;
> $keep = ~$mask & $oldval;
> $newval = $keep | $add;
>
> // show what happened
> var_dump(
> str_pad(base_convert($oldval, 10, 2), 8, "0"),
> str_pad(base_convert($update, 10, 2), 8, "0"),
> str_pad(base_convert($mask, 10, 2), 8, "0"),
> str_pad(base_convert($add, 10, 2), 8, "0"),
> str_pad(base_convert($keep, 10, 2), 8, "0"),
> str_pad(base_convert($newval, 10, 2), 8, "0")
> );
>
> ?>
>
>>
>> How do I combine A, B and C to get that result?
>>
>>
>> Thanks,
>> Niels
>>

Thanks, I appreciate your effort! Working code with inlined pun -- very
nice!

Regards,
Niels

attached mail follows:


On Tuesday 13 June 2006 12:18, David Tulloh wrote:

> The example starting values
> $existing = 181; # = 10110101
> $new = 92; # = 01011100
> $mask = 15; # = 00001111
>
> Get the bits that will be changed
> $changing = $new & $mask; # = 12 = 00001100
>
> Get the bits that won't be changed
> $staying = $existing & ~$mask; # = 176 = 10110000
>
> Combine them together
> $result = $changing ^ $staying; # = 188 = 10111100
>
>
> David
[snip]

Thank you very much, I appreciate it!

Niels

attached mail follows:


----- Original Message -----
From: "David Tulloh" <davidtulloh.id.au>
To: <zorglub_olsenhotmail.com>
Cc: <php-generallists.php.net>
Sent: Tuesday, June 13, 2006 12:18 PM
Subject: Re: [PHP] Help with some clever bit operations

> The example starting values
> $existing = 181; # = 10110101
> $new = 92; # = 01011100
> $mask = 15; # = 00001111
>
> Get the bits that will be changed
> $changing = $new & $mask; # = 12 = 00001100
>
> Get the bits that won't be changed
> $staying = $existing & ~$mask; # = 176 = 10110000
>
> Combine them together
> $result = $changing ^ $staying; # = 188 = 10111100
>
>
> David
>

Though the result is the same, logically a bitwise OR (|) would be more
appropriate. The bitwise XOR flips bits which, since in this case one set
of them is always 0 produces the same result. The bitwise OR adds the bits.

An informal set of rules is:

&, as a filter, extracts those bits where you put ones in the mask
& sets to zero those bits where you put zero in the mask
| sets bits
^ flips the bits where you put a one.

$evenodd & 1 is true on odd numbers or otherwise tests for the rightmost
bit. Coupled with a right shift >> allows you to loop through a set of
bits.

for ($i=0;$i<32;$i++) {
    if ($bitset & 1) {
        echo "bit $i is set";
    }
    $bitset >>= 1;
}

Anyway, avoid the most significant bit. Since in PHP there are no unsigned
integers, you might get some funny result if anything makes PHP do an
automatic type conversion.

Satyam

attached mail follows:


On Tue, 2006-06-13 at 06:22, Jochem Maas wrote:
>
> My brain needs a crutch when trying doing this kind of thing
> (normally I only write hex number literally when dealing with bitwise stuff -
> the conversion stuff still makes my head spin) - this is what this table is for:
>
> 128 64 32 16 8 4 2 1
> 1 0 1 1 0 1 0 1
> 0 1 0 1 1 1 0 0
> 0 0 0 0 1 1 1 1
>
> and then I did this - hopefully it shows what you can/have to do:
>
> <?php
>
> // set some values
> $oldval = 128 + 32 + 16 + 4 + 1; // 10110101
> $update = 64 + 16 + 8 + 4; // 01011100
> $mask = 8 + 4 + 2 + 1; // 00001111

You could just do the following:

$oldval = bindec( '10110101' );
$update = bindec( '01011100' );
$mask = bindec( '00001111' );

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

attached mail follows:


Robert Cummings wrote:
> On Tue, 2006-06-13 at 06:22, Jochem Maas wrote:
>> My brain needs a crutch when trying doing this kind of thing
>> (normally I only write hex number literally when dealing with bitwise stuff -
>> the conversion stuff still makes my head spin) - this is what this table is for:
>>
>> 128 64 32 16 8 4 2 1
>> 1 0 1 1 0 1 0 1
>> 0 1 0 1 1 1 0 0
>> 0 0 0 0 1 1 1 1
>>
>> and then I did this - hopefully it shows what you can/have to do:
>>
>> <?php
>>
>> // set some values
>> $oldval = 128 + 32 + 16 + 4 + 1; // 10110101
>> $update = 64 + 16 + 8 + 4; // 01011100
>> $mask = 8 + 4 + 2 + 1; // 00001111
>
> You could just do the following:
>
> $oldval = bindec( '10110101' );
> $update = bindec( '01011100' );
> $mask = bindec( '00001111' );

when I was writing the reply I played with about 5 different
conversion funcs - pretty everything expect bindec() !!!

I guess i was being lazy - but then I alway think directly in hex numbers
when doing bitwise stuff (at least I use hex notation for the constant value
that I almost invariably end up creating)

anyway cheers for the lightbuld moment :-)

>
> Cheers,
> Rob.

attached mail follows:


On Tue, 2006-06-13 at 11:03, Jochem Maas wrote:
> Robert Cummings wrote:
> > On Tue, 2006-06-13 at 06:22, Jochem Maas wrote:
> >> My brain needs a crutch when trying doing this kind of thing
> >> (normally I only write hex number literally when dealing with bitwise stuff -
> >> the conversion stuff still makes my head spin) - this is what this table is for:
> >>
> >> 128 64 32 16 8 4 2 1
> >> 1 0 1 1 0 1 0 1
> >> 0 1 0 1 1 1 0 0
> >> 0 0 0 0 1 1 1 1
> >>
> >> and then I did this - hopefully it shows what you can/have to do:
> >>
> >> <?php
> >>
> >> // set some values
> >> $oldval = 128 + 32 + 16 + 4 + 1; // 10110101
> >> $update = 64 + 16 + 8 + 4; // 01011100
> >> $mask = 8 + 4 + 2 + 1; // 00001111
> >
> > You could just do the following:
> >
> > $oldval = bindec( '10110101' );
> > $update = bindec( '01011100' );
> > $mask = bindec( '00001111' );
>
> when I was writing the reply I played with about 5 different
> conversion funcs - pretty everything expect bindec() !!!
>
> I guess i was being lazy - but then I alway think directly in hex numbers
> when doing bitwise stuff (at least I use hex notation for the constant value
> that I almost invariably end up creating)
>
> anyway cheers for the lightbuld moment :-)

Well yours is at least faster since there's no function calls. Though
one can also do the following to avoid memorizing decimal bit values :)

$oldval = (1 << 7) + (1 << 5) + (1 << 4) + (1 << 2) + (1 << 0);
$update = (1 << 6) + (1 << 4) + (1 << 3) + (1 << 2);
$mask = (1 << 3) + (1 << 2) + (1 << 1) + (1 << 0);

:)

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

attached mail follows:


Robert Cummings wrote:
> On Tue, 2006-06-13 at 11:03, Jochem Maas wrote:
>> Robert Cummings wrote:
>>> On Tue, 2006-06-13 at 06:22, Jochem Maas wrote:
>>>> My brain needs a crutch when trying doing this kind of thing
>>>> (normally I only write hex number literally when dealing with bitwise stuff -
>>>> the conversion stuff still makes my head spin) - this is what this table is for:
>>>>
>>>> 128 64 32 16 8 4 2 1
>>>> 1 0 1 1 0 1 0 1
>>>> 0 1 0 1 1 1 0 0
>>>> 0 0 0 0 1 1 1 1
>>>>
>>>> and then I did this - hopefully it shows what you can/have to do:
>>>>
>>>> <?php
>>>>
>>>> // set some values
>>>> $oldval = 128 + 32 + 16 + 4 + 1; // 10110101
>>>> $update = 64 + 16 + 8 + 4; // 01011100
>>>> $mask = 8 + 4 + 2 + 1; // 00001111
>>> You could just do the following:
>>>
>>> $oldval = bindec( '10110101' );
>>> $update = bindec( '01011100' );
>>> $mask = bindec( '00001111' );
>> when I was writing the reply I played with about 5 different
>> conversion funcs - pretty everything expect bindec() !!!
>>
>> I guess i was being lazy - but then I alway think directly in hex numbers
>> when doing bitwise stuff (at least I use hex notation for the constant value
>> that I almost invariably end up creating)
>>
>> anyway cheers for the lightbuld moment :-)
>
> Well yours is at least faster since there's no function calls. Though
> one can also do the following to avoid memorizing decimal bit values :)
>
> $oldval = (1 << 7) + (1 << 5) + (1 << 4) + (1 << 2) + (1 << 0);
> $update = (1 << 6) + (1 << 4) + (1 << 3) + (1 << 2);
> $mask = (1 << 3) + (1 << 2) + (1 << 1) + (1 << 0);

cool - more brainfood. thanks!

>
> :)
>
> Cheers,
> Rob.

attached mail follows:


$BLS$b$^$8$($F$J$$;R$N%^%s;R$O!*(B

$B40A4L5=$5%5%s%W%kF02h$G3NG'$7$F!"5$$KF~$C$?;R$r$*B_$7$7$^$9!#(B

$BNA6b$O!"0[Nc$N#5#0J,#5#0#0#01_!*!*(B

$B>\:Y$O7G<(HD$r8+$F$4O"Mm$/$$5$$(B

http://vqlh.com/?by69

$B#N#o#3#4#7#4#9#2(B








































$B5qH](B
k_49singing_in_the_rainyahoo.co.uk


attached mail follows:


PHP List,

Up until now, in order to get all the functions and classes I need in my
scripts, I have always made a file called "includes.php" that contains a
series of include() statements for all of the files that I want to
include. Then I just include that one file at the top of all my PHP scripts.

This system works okay, but I thought it would be better to have a
consistent naming standard, and use some kind wild card or loop to
include all the files I want. That way I can change, add, and remove
files a little easier.

All the files I want to include end with either ".class", or with
"_fns.php". ("fns" stands for "functions".)

It seems that wildcard characters are not supported in the include()
function. Some experiments and a search on the web seem to confirm this.

So then I thought what I need to do is use the readdir() function
somehow, and make an array of all files ending in ".class" or
"_fns.php", and then make a while or foreach loop to include every
required file.

I couldn't quite figure out how to do that, but in any case I wondered
if running this loop at the start of every single PHP script might be
unnecessary overhead. After all, the list of included files will only
change when I work on the system. It's not going to vary at all based on
any kind of user input or in standard usage of my web site.

What would be the recommended way of including files that will change as
I work on the system? Do most people create a function to detect the
included files, or do most people make a static list that they edit by hand?

--
Dave M G

attached mail follows:


At 7:22 PM +0900 6/13/06, Dave M G wrote:
>PHP List,
>
>Up until now, in order to get all the functions and classes I need in my scripts, I have always made a file called "includes.php" that contains a series of include() statements for all of the files that I want to include. Then I just include that one file at the top of all my PHP scripts.
>
>This system works okay, but I thought it would be better to have a consistent naming standard, and use some kind wild card or loop to include all the files I want. That way I can change, add, and remove files a little easier.
>
>All the files I want to include end with either ".class", or with "_fns.php". ("fns" stands for "functions".)
>
>It seems that wildcard characters are not supported in the include() function. Some experiments and a search on the web seem to confirm this.
>
>So then I thought what I need to do is use the readdir() function somehow, and make an array of all files ending in ".class" or "_fns.php", and then make a while or foreach loop to include every required file.
>
>I couldn't quite figure out how to do that, but in any case I wondered if running this loop at the start of every single PHP script might be unnecessary overhead. After all, the list of included files will only change when I work on the system. It's not going to vary at all based on any kind of user input or in standard usage of my web site.
>
>What would be the recommended way of including files that will change as I work on the system? Do most people create a function to detect the included files, or do most people make a static list that they edit by hand?
>
>--
>Dave M G

Dave:

I group my includes per functionality, such as all dB operations (config, open, close, etc.) go into a db include folder (db_inc) and so on. I don't make large files, but rather small files limited to a specific operations. That works for me -- but, only you can figure out what works for you.

As for your code, try this:

<?php

        $file_path = $_SERVER['DOCUMENT_ROOT']; // or whatever directory you want
        $the_dir = opendir($file_path);

        while ($file = readdir($the_dir))
                {
                if(eregi("(\.pdf|\.html|\.htm|\.php|\.txt)$", $file)) // check the files extension:
                        {
                        $html[] = $file;
                        }
                }

        closedir($the_dir);

        if($html == null)
                {
                die("No files in this directory!");
                }
                
        sort($html);
        foreach($html as $html => $value)
                {
                echo ("<br/> $value");
                }
?>

hth's

tedd
--
------------------------------------------------------------------------------------
http://sperling.com http://ancientstones.com http://earthstones.com

attached mail follows:


        Anyway when you include files by script (not scpecifying the order in
which u include them) check out class inheritage and class usage in
files you include. Classes that are inherited must be included first.

        Andy

At 7:22 PM +0900 6/13/06, Dave M G wrote:
>PHP List,
>
>Up until now, in order to get all the functions and classes I need in my scripts, I have always made a file called "includes.php" that contains a series of include() statements for all of the files that I want to include. Then I just include that one file at the top of all my PHP scripts.
>
>This system works okay, but I thought it would be better to have a consistent naming standard, and use some kind wild card or loop to include all the files I want. That way I can change, add, and remove files a little easier.
>
>All the files I want to include end with either ".class", or with "_fns.php". ("fns" stands for "functions".)
>
>It seems that wildcard characters are not supported in the include() function. Some experiments and a search on the web seem to confirm this.
>
>So then I thought what I need to do is use the readdir() function somehow, and make an array of all files ending in ".class" or "_fns.php", and then make a while or foreach loop to include every required file.
>
>I couldn't quite figure out how to do that, but in any case I wondered if running this loop at the start of every single PHP script might be unnecessary overhead. After all, the list of included files will only change when I work on the system. It's not going to vary at all based on any kind of user input or in standard usage of my web site.
>
>What would be the recommended way of including files that will change as I work on the system? Do most people create a function to detect the included files, or do most people make a static list that they edit by hand?
>
>--
>Dave M G

Dave:

I group my includes per functionality, such as all dB operations
(config, open, close, etc.) go into a db include folder (db_inc) and so
on. I don't make large files, but rather small files limited to a
specific operations. That works for me -- but, only you can figure out
what works for you.

As for your code, try this:

<?php

        $file_path = $_SERVER['DOCUMENT_ROOT']; // or whatever directory you want
        $the_dir = opendir($file_path);

        while ($file = readdir($the_dir))
                {
                if(eregi("(\.pdf|\.html|\.htm|\.php|\.txt)$", $file)) // check the
files extension:
                        {
                        $html[] = $file;
                        }
                }

        closedir($the_dir);

        if($html == null)
                {
                die("No files in this directory!");
                }
                
        sort($html);
        foreach($html as $html => $value)
                {
                echo ("<br/> $value");
                }
?>

hth's

tedd

attached mail follows:


Hi,

I am using gettext to get a web page in several languages.

When gettext does not found an string, it shows the string.

Is it possible to detect when a string is not found, in order to advis me ?

Thanks in advance,
Ruben Rubio Rey

attached mail follows:


Ruben Rubio Rey wrote:
> Hi,
>
> I am using gettext to get a web page in several languages.
>
> When gettext does not found an string, it shows the string.
>
> Is it possible to detect when a string is not found, in order to advis me ?

sure in a very simplistic manner;

function __($s)
{
        $r = _($s);
        if ($r === $s) logUntranslatedStr($s);
        
        return $r;
}

but the php gettext extension does not seem to provide such a functionality
natively.

>
> Thanks in advance,
> Ruben Rubio Rey
>

attached mail follows:


Best group member,

This is how I try to push files to download using headers:

header("Content-type: $file_type");
header("Content-Disposition: attachment; filename=$filename");
print $file;

It works fine in FireFox, but not that good in IE. I have been googled to
find the fix for IE, but I can not find it. Anyone with experience of this?

Best regards,
Peter Lauri

attached mail follows:


--- Larry Garfield <larrygarfieldtech.com> wrote:

<clip 1>
> > > that said it could take a week to figure out all
> the
> > > parameters. ;-)
> >
</clip 1>

...

</clip 2>
> That's why I included the switches I did. :-) I had
> to do something very
> similar just last week.

> ...
>
> -m means "mirror". That is, recurse to all links
> that don't leave the domain.
> It's for exactly this sort of task.
>
> -k tells it to convert links. That way if you have
> all absolute links in your
> HTML output, it will mutate them for you to stay
> within the local mirror
> you're creating.
>
> If you have GET queries in your pages (we did), then
> I recommend also using:
>
> --restrict-file-names=windows
>
> That will tell it to convert any blah?foo=bar links
> into blahfoo=bar, since
> the first is not a valid filename in Windows. I
> find that even on a Linux
> box, the latter works better.

</clip 2>

Hey,
Thanks for the explanation of the switches.

One part that I dont really understand is:

 blah?foo=bar links
 into blahfoo=bar

having a link such as blahfoo=bar is not going to
work to link to the second document...right? (I have
not really tried it, but have never seen html like the
above)

And lastly, I read on another forum discussing wget
that there is a switch that converts the dynamic pages
to static WITH a .html/.htm extention; unfortunatly he
didnt give an example of how to do this, was he just
blowing smoke or is that true?

Thanks again,
Ryan

------
- The faulty interface lies between the chair and the keyboard.
- Creativity is great, but plagiarism is faster!
- Smile, everyone loves a moron. :-)

__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com

attached mail follows:


On Tuesday 13 June 2006 07:22, Ryan A wrote:

> Hey,
> Thanks for the explanation of the switches.
>
> One part that I dont really understand is:
>
> blah?foo=bar links
> into blahfoo=bar
>
> having a link such as blahfoo=bar is not going to
> work to link to the second document...right? (I have
> not really tried it, but have never seen html like the
> above)

Actually for me it didn't work until I did that conversion. You're not
sending an actual variable query, remember. You're linking to a static file
whose name on disk is "blahfoo=bar", which is a valid filename,
while "blah?foo=bar" is not (at least under Windows, although it didn't work
for me under Unix either).

> And lastly, I read on another forum discussing wget
> that there is a switch that converts the dynamic pages
> to static WITH a .html/.htm extention; unfortunatly he
> didnt give an example of how to do this, was he just
> blowing smoke or is that true?

man wget, and look for the -E option (aka --html-extension).

--
Larry Garfield AIM: LOLG42
larrygarfieldtech.com ICQ: 6817012

"If nature has made any one thing less susceptible than all others of
exclusive property, it is the action of the thinking power called an idea,
which an individual may exclusively possess as long as he keeps it to
himself; but the moment it is divulged, it forces itself into the possession
of every one, and the receiver cannot dispossess himself of it." -- Thomas
Jefferson

attached mail follows:


First of all I'm sorry for my english I don't know speak very well, I will
try to explain it, I hope you understain what I need.

I have two tables: centers and peoples, in table centers I have the centers
values and in table peoples I have the peoples values and in table columns
center the id corresponding the center.

db:
centers
id namec correoc telc
1 Cienfuegos safdcomo.com 4534345
2 Havana wdqcomo.com 4643765
3 Santiago dsdfcomo.com 3453453

peoples
id named center correod
cargod
1 Albert 1 dfsasdcomo.com
sfgsdfgsdfgsdfg
2 Julio 1 wdfsdfcomo.com
sadfsgfdsfgfdsg
3 Sussan 2 efgedfgcomo.com
gjfhjfhjfhjfg
4 Peter 2 fgdfdfgcomo.com
fgjhfgjgfjhjjghj

And the query and script to generate the tables for each centers list is:

$centers = mysql_query("SELECT namec FROM centers ORDER BY idc asc",
$connect);

while ($centerss = mysql_fetch_array($centers, MYSQL_ASSOC)) {
   echo "<table border=1>";
    echo "<tr>";
        echo "<td width=265 height=20 align=center
valign=middle>".$centerss['namec']."</td>";
        echo "<td width=265 height=20 align=center valign=middle><a
href=mailto:".$centerss['correoc'].">".$centerss['correoc']."</a></td>";
        echo "<td width=265 height=20 align=center
valign=middle>".$centerss['telc']."</td>";
    echo "</tr>";
        echo "</table><p></p>";
}
mysql_free_result($centers);

That's generate one table with one row and three columns for each center,
but, I would like to generate more rows and 3 columns in each table with the
named, correod and cargod of peoples corresponding the center, I mean, print
the centers values with the peoples corresponding this center, in one table
each one.

I hope you understaind what I need, if not polease let me know.

regards Alain

--
Este mensaje ha sido analizado por MailScanner
en busca de virus y otros contenidos peligrosos,
y se considera que está limpio.

attached mail follows:


if you want to ask a question don't be so lazy as to
simply reply to a post in an existing thread - it's considered
rude.

send a new email.

Jesús Alain Rodríguez Santos wrote:

...

attached mail follows:


Your query is wrong. You are selecting only one result yet you are
referencing three. I suggest...

SELECT * FROM centers ORDER BY idc asc

Jef

-----Original Message-----
From: Jesús Alain Rodríguez Santos [mailto:wmastercfg.jovenclub.cu]
Sent: Tuesday, June 13, 2006 8:49 AM
To: php-generallists.php.net
Subject: [PHP] Please help me with a query

First of all I'm sorry for my english I don't know speak very well, I will
try to explain it, I hope you understain what I need.

I have two tables: centers and peoples, in table centers I have the centers
values and in table peoples I have the peoples values and in table columns
center the id corresponding the center.

db:
centers
id namec correoc telc
1 Cienfuegos safdcomo.com 4534345
2 Havana wdqcomo.com 4643765
3 Santiago dsdfcomo.com 3453453

peoples
id named center correod
cargod
1 Albert 1 dfsasdcomo.com
sfgsdfgsdfgsdfg
2 Julio 1 wdfsdfcomo.com
sadfsgfdsfgfdsg
3 Sussan 2 efgedfgcomo.com
gjfhjfhjfhjfg
4 Peter 2 fgdfdfgcomo.com
fgjhfgjgfjhjjghj

And the query and script to generate the tables for each centers list is:

$centers = mysql_query("SELECT namec FROM centers ORDER BY idc asc",
$connect);

while ($centerss = mysql_fetch_array($centers, MYSQL_ASSOC)) {
   echo "<table border=1>";
    echo "<tr>";
        echo "<td width=265 height=20 align=center
valign=middle>".$centerss['namec']."</td>";
        echo "<td width=265 height=20 align=center valign=middle><a
href=mailto:".$centerss['correoc'].">".$centerss['correoc']."</a></td>";
        echo "<td width=265 height=20 align=center
valign=middle>".$centerss['telc']."</td>";
    echo "</tr>";
        echo "</table><p></p>";
}
mysql_free_result($centers);

That's generate one table with one row and three columns for each center,
but, I would like to generate more rows and 3 columns in each table with the
named, correod and cargod of peoples corresponding the center, I mean, print
the centers values with the peoples corresponding this center, in one table
each one.

I hope you understaind what I need, if not polease let me know.

regards Alain

--
Este mensaje ha sido analizado por MailScanner
en busca de virus y otros contenidos peligrosos,
y se considera que está limpio.

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

attached mail follows:


Hi all,
I found out (while playing with xpath()) that you cant edit the content of a node when you use a reference on a SimpleXMLElement object.
An example:
---------------------------
$xmlString = '<?xml version="1.0" encoding="UTF-8"?>
  <container>
   <texte>
    <text user="user1">llllasdfasdfeorpqi</text>
    <text user="user2">oouzzrrzreorpqi</text>
  </texte>
</container>';

$xml = simplexml_load_string($xmlString);
$xml->texte->text[0] = 'newText'; // Works
$xml->texte->text[0]['user'] = 'newUser'; // Works
echo $xml->asXML() . "\n";

$xml = simplexml_load_string($xmlString);
$xmlRef = $xml->texte->text[0]; // Creating a reference
$xmlRef['user'] = 'newUser'; // Works
$xmlRef = 'newUser'; // Doesnt Work!
echo $xml->asXML() . "\n";
---------------------------
Am i doing something wrong. or is this a bug or what ?

Hope for some help

Bye
Georg Nagel

attached mail follows:


How can I send UTF-8 mails with the mail() function. Right now I am doing:

mail('theemaildomain.com', 'Subject', 'Message',
"From: The Sender <senderdomain.com> \n" .
"Content-Type: text/plain; charset=utf-8 \n" .
"Content-Transfer-Encoding: 7bit\n\n")

The message is being sent, but the UTF-8 specific characters are not being
presented. Is there any fix on this?

The messages etc are coming from a form. Is it possible to set the charset
for the form?

/Peter

attached mail follows:


Peter Lauri schrieb:
> How can I send UTF-8 mails with the mail() function. Right now I am doing:
>
> mail('theemaildomain.com', 'Subject', 'Message',
> "From: The Sender <senderdomain.com> \n" .
> "Content-Type: text/plain; charset=utf-8 \n" .
> "Content-Transfer-Encoding: 7bit\n\n")
>
> The message is being sent, but the UTF-8 specific characters are not being
> presented. Is there any fix on this?
>
> The messages etc are coming from a form. Is it possible to set the charset
> for the form?
>
> /Peter
$bodytext = utf8_encode($bodytext);
--
Smileys rule (cX.x)C --o(^_^o)
Dance for me! ^(^_^)o (o^_^)o o(^_^)^ o(^_^o)

attached mail follows:


That worked "better". Now I at least am getting something that looks like
the same it looks in MySQL database table. However, in the email client
(outlook, gmail, hotmail) it is being showed like this:

Document name: ´¡¿Ë
Document summary: ´¡Ë¿

/Peter

-----Original Message-----
From: Barry [mailto:barryflyerheaven.de]
Sent: Tuesday, June 13, 2006 9:34 PM
To: php-generallists.php.net
Subject: [PHP] Re: Sending UTF-8 mail with mail()

Peter Lauri schrieb:
> How can I send UTF-8 mails with the mail() function. Right now I am doing:
>
> mail('theemaildomain.com', 'Subject', 'Message',
> "From: The Sender <senderdomain.com> \n" .
> "Content-Type: text/plain; charset=utf-8 \n" .
> "Content-Transfer-Encoding: 7bit\n\n")
>
> The message is being sent, but the UTF-8 specific characters are not being
> presented. Is there any fix on this?
>
> The messages etc are coming from a form. Is it possible to set the charset
> for the form?
>
> /Peter
$bodytext = utf8_encode($bodytext);
--
Smileys rule (cX.x)C --o(^_^o)
Dance for me! ^(^_^)o (o^_^)o o(^_^)^ o(^_^o)

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

attached mail follows:


At 5:25 PM +0700 6/13/06, Peter Lauri wrote:
>That worked "better". Now I at least am getting something that looks like
>the same it looks in MySQL database table. However, in the email client
>(outlook, gmail, hotmail) it is being showed like this:
>
>Document name: ´¡¿Ë
>Document summary: ´¡Ë¿
>
>/Peter
>

Does the output's font contains those characters?

tedd
--
------------------------------------------------------------------------------------
http://sperling.com http://ancientstones.com http://earthstones.com

attached mail follows:


Adam Zey wrote:

> Christopher J. Bottaro wrote:
>> Hello,
>> How can I trap a fatal error (like calling a non existant method,
>> requiring
>> a non existant file, etc) and go to a user defined error handler? I
>> tried set_error_handler(), but it seems to skip over the errors I care
>> about.
>>
>> Thanks for the help.
>
> It is always safer to handle errors before they happen by checking that
> you're in a good state before you try to do something.
>
> For example, nonexistent files can be handled by file_exists().
> Undefined functions can be checked with function_exists().
>
> Regards, Adam Zey.

Well, I know that.

Sometimes unexpected errors happen. We write hundreds of lines of code a
day. Typos happen, I forget some includes, I type $d->appendCild() instead
of $d->appendChild(). It's all a part of the development process.

Our application makes extensive use of AJAX and JSON. Sometimes we make an
AJAX request and expect a JSON object in return, but instead a fatal error
happens (DOMDocument::appendChid() does not exist), well now we get a JSON
error because the response headers were messed up by the fatal error.

That JSON error is useless. We would rather see the real error as PHP would
have reported it on a simple webpage or command line.

Basically, we just want to trap all errors and reraise them as exceptions so
that our app's default exception handler can report them.

Thanks.

attached mail follows:


> Sometimes unexpected errors happen. We write hundreds of lines of code a
> day. Typos happen, I forget some includes, I type $d->appendCild() instead
> of $d->appendChild(). It's all a part of the development process.
>
> Our application makes extensive use of AJAX and JSON. Sometimes we make an
> AJAX request and expect a JSON object in return, but instead a fatal error
> happens (DOMDocument::appendChid() does not exist), well now we get a JSON
> error because the response headers were messed up by the fatal error.
>
> That JSON error is useless. We would rather see the real error as PHP would
> have reported it on a simple webpage or command line.
>
> Basically, we just want to trap all errors and reraise them as exceptions so
> that our app's default exception handler can report them.

I read what you said and understand where you are coming from, but if
you call a function and it doesn't exist, your script is going to die.
 The only thing you can do is just tail your error log and write unit
tests to make sure your stuff is working right. If you are on a local
machine just keep an eye on your php error log on each request and you
will see the full error message if log errors is turned on.

attached mail follows:


Christopher J. Bottaro wrote:
> Adam Zey wrote:
>
>> Christopher J. Bottaro wrote:
>>> Hello,
>>> How can I trap a fatal error (like calling a non existant method,
>>> requiring
>>> a non existant file, etc) and go to a user defined error handler? I
>>> tried set_error_handler(), but it seems to skip over the errors I care
>>> about.
>>>
>>> Thanks for the help.
>> It is always safer to handle errors before they happen by checking that
>> you're in a good state before you try to do something.
>>
>> For example, nonexistent files can be handled by file_exists().
>> Undefined functions can be checked with function_exists().
>>
>> Regards, Adam Zey.
>
> Well, I know that.
>
> Sometimes unexpected errors happen. We write hundreds of lines of code a
> day. Typos happen, I forget some includes, I type $d->appendCild() instead
> of $d->appendChild(). It's all a part of the development process.
>
> Our application makes extensive use of AJAX and JSON. Sometimes we make an
> AJAX request and expect a JSON object in return, but instead a fatal error
> happens (DOMDocument::appendChid() does not exist), well now we get a JSON
> error because the response headers were messed up by the fatal error.
>
> That JSON error is useless. We would rather see the real error as PHP would
> have reported it on a simple webpage or command line.
>
> Basically, we just want to trap all errors and reraise them as exceptions so
> that our app's default exception handler can report them.

for fatal errors this not possible.

write test routines to check the output of requests that are usually made by
AJAX code... and made use a function like this to cover all your bases:

function PHPErrorReturned(response)
{
    // this is a bit crude and could possibly break if we are recieving
    // [content] HTML as part of the returned data.
    if ((response.indexOf('<b>Notice</b>: ') ||
         response.indexOf('<b>Warning</b>: ') ||
         response.indexOf('<b>Fatal Error</b>: ')) && (response.indexOf('{') != 0))
    {
        alert("Er was een fout opgetreden op de server\n"+response.stripTags());
        return true;
    }

    return false;
}

String.prototype.stripTags = function (validTags)
{
    var newstr = this.toString();
    var regExp1 = /<\/?(\w+)(.*?)>/ig;

    if (validTags && validTags.prototype == Array) {
        var regExp2 = new RegExp('/^('+validTags.join('|')+')$/i'); // em|strong|u|p
    }

    while(mt = regExp1.exec(newstr)) {
        oldstr = mt[0]; tag = mt[1]; pars = mt[2];
        repl = '';

        if(regExp2 && tag.match(regExp2)) {
            repl = oldstr.replace(pars,'');
        }

        newstr = newstr.replace(oldstr, repl);
    }
    return newstr;
}

>
> Thanks.
>

attached mail follows:


Jochem Maas wrote:

> Christopher J. Bottaro wrote:
>> Adam Zey wrote:
>>
>>> Christopher J. Bottaro wrote:
>>>> Hello,
>>>> How can I trap a fatal error (like calling a non existant method,
>>>> requiring
>>>> a non existant file, etc) and go to a user defined error handler? I
>>>> tried set_error_handler(), but it seems to skip over the errors I care
>>>> about.
>>>>
>>>> Thanks for the help.
>>> It is always safer to handle errors before they happen by checking that
>>> you're in a good state before you try to do something.
>>>
>>> For example, nonexistent files can be handled by file_exists().
>>> Undefined functions can be checked with function_exists().
>>>
>>> Regards, Adam Zey.
>>
>> Well, I know that.
>>
>> Sometimes unexpected errors happen. We write hundreds of lines of code a
>> day. Typos happen, I forget some includes, I type $d->appendCild()
>> instead
>> of $d->appendChild(). It's all a part of the development process.
>>
>> Our application makes extensive use of AJAX and JSON. Sometimes we make
>> an AJAX request and expect a JSON object in return, but instead a fatal
>> error happens (DOMDocument::appendChid() does not exist), well now we get
>> a JSON error because the response headers were messed up by the fatal
>> error.
>>
>> That JSON error is useless. We would rather see the real error as PHP
>> would have reported it on a simple webpage or command line.
>>
>> Basically, we just want to trap all errors and reraise them as exceptions
>> so that our app's default exception handler can report them.
>
> for fatal errors this not possible.
>
> write test routines to check the output of requests that are usually made
> by AJAX code... and made use a function like this to cover all your bases:
>
> function PHPErrorReturned(response)
> {
> // this is a bit crude and could possibly break if we are recieving
> // [content] HTML as part of the returned data.
> if ((response.indexOf('<b>Notice</b>: ') ||
> response.indexOf('<b>Warning</b>: ') ||
> response.indexOf('<b>Fatal Error</b>: ')) &&
> (response.indexOf('{') != 0))
> {
> alert("Er was een fout opgetreden op de
> server\n"+response.stripTags()); return true;
> }
>
> return false;
> }
>
> String.prototype.stripTags = function (validTags)
> {
> var newstr = this.toString();
> var regExp1 = /<\/?(\w+)(.*?)>/ig;
>
> if (validTags && validTags.prototype == Array) {
> var regExp2 = new RegExp('/^('+validTags.join('|')+')$/i'); //
> em|strong|u|p
> }
>
> while(mt = regExp1.exec(newstr)) {
> oldstr = mt[0]; tag = mt[1]; pars = mt[2];
> repl = '';
>
> if(regExp2 && tag.match(regExp2)) {
> repl = oldstr.replace(pars,'');
> }
>
> newstr = newstr.replace(oldstr, repl);
> }
> return newstr;
> }
>
>
>
>
>>
>> Thanks.

Cool, that sounds promising, thanks for that idea (and everyone else who
replied).

attached mail follows:


Hi all

Not really a php issue per se - sorry.
But I'm sure someone here is bound to know the answer. :-)

I have a main site that is accessible at say
"http://www.somedomain.com/somedir/" but I want visitors to be able to
access the site using simply "http://www.somedomain.com" AND for the
resulting URL displayed to STILL say "http://www.somedomain.com" and not
"http://www.somedomain.com/somedir/".

Should this be possible using the .htaccess file and some mod_rewrite rule?
Toyed around with that but couldn't get it to work.

ANY help would be greatly appreciated, thanks

P.S. Platform: Linux RedHat (running Apache)

scorpy

attached mail follows:


Keith wrote:
> Hi all
>
> Not really a php issue per se - sorry.
> But I'm sure someone here is bound to know the answer. :-)
>
> I have a main site that is accessible at say
> "http://www.somedomain.com/somedir/" but I want visitors to be able to
> access the site using simply "http://www.somedomain.com" AND for the
> resulting URL displayed to STILL say "http://www.somedomain.com" and not
> "http://www.somedomain.com/somedir/".
>
> Should this be possible using the .htaccess file and some mod_rewrite rule?
> Toyed around with that but couldn't get it to work.

when you finished toying did you take time to read the Apache docs on mod_rewrite?

you need *something like*:

RewriteRule ^/(.*)$ /somedir/$1 [L]

>
> ANY help would be greatly appreciated, thanks
>
> P.S. Platform: Linux RedHat (running Apache)
>
> scorpy
>

attached mail follows:


KI wrote:
> I posted this Thursday as a PHP bug: http://bugs.php.net/bug.php?id=37743
>
> Basically this function is off by 2 minutes from the US & UK governments
> calculations.

not today it isn't - U.S. Naval Observatory (http://aa.usno.navy.mil/data/docs/RS_OneDay.html)
gives me 5.23 for sunrise with the data you gave in your bug report.

I suggest you take dericks' words on it that this is a very difficult
algorithm and that this cannot easily, if at all, be 'fixed' (if it is
even actually a bug).

and besides since when were either of those govs considered trustworthy?
as far as authoritive sources are concerned they are right up there with
wikipedia and google.

and like like Einstein said - time is relative. so what is 5.22 anyway?

> While PHP is admitting there is a difference they are stating
> I should live with it and "it's expected". Does any one else not find this
> acceptable?

about as acceptable as the number of vowels in your domain name.
(it remains a fact whether one 'accepts' it or not)

What can be done to push PHP to correct this?

nothing, unless you can provide a patch.

there is a reason why php is not used to track satellites or shuttle
reentries and the like... and 60 seconds off on the sunrise calculation on some
webpage is not exactly going to stop the world from rotating is it?

>
> Thanks
>

attached mail follows:


Beauford wrote:
> I'm using Slackware 10 and installed GD as an install package. I also
> changed some lines in the php.ini file for GD.
>
> Tom: I have no idea how this program works, all I know is that I need it for
> the captcha program to display the image. I wouldn't even bother otherwise.
>
> Thanks.....
>
> B
>
>
>
Well, do you know where it is installed? I have mine installed in
/usr/local/gd so to test it I just ran gd2topng via
/usr/local/gd/bin/gd2topng it will ask for image information etc. If it
does that then you're golden.

The downside is you will need to recompile PHP.