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 23 Aug 2005 12:38:32 -0000 Issue 3641

php-general-digest-helplists.php.net
Date: Tue Aug 23 2005 - 07:38:32 CDT


php-general Digest 23 Aug 2005 12:38:32 -0000 Issue 3641

Topics (messages 221128 through 221160):

Re: Files passing through
        221128 by: Jasper Bryant-Greene
        221135 by: Richard Lynch
        221145 by: Kim Steinhaug \(php list\)
        221148 by: Jasper Bryant-Greene
        221151 by: Richard Lynch
        221154 by: Jasper Bryant-Greene

foreach loop changed after 4.3 -> 4.4 upgrade
        221129 by: Larry Brown
        221130 by: Larry Brown
        221156 by: Ford, Mike

Large URI request problem
        221131 by: Dean Maunder
        221132 by: Jasper Bryant-Greene
        221137 by: Dean Maunder
        221138 by: Dean Maunder
        221140 by: Jasper Bryant-Greene
        221141 by: Dean Maunder
        221152 by: Richard Lynch

Re: Resizing thumbnails to the browser
        221133 by: Richard Lynch

Re: PHP Printing Error Help
        221134 by: Richard Lynch

Re: PHP vs. ColdFusion
        221136 by: Richard Lynch

Re: Problem appending values to an object
        221139 by: Richard Lynch

Re: preg_match
        221142 by: Richard Lynch
        221153 by: Robin Vickery
        221155 by: Jasper Bryant-Greene
        221157 by: Robin Vickery

Re: Special HTML characters question.
        221143 by: Richard Lynch

Re: Looking for CMS advice
        221144 by: Richard Lynch
        221146 by: Kim Steinhaug \(php list\)
        221147 by: Raz

Re: imagestring to picture
        221149 by: Richard Lynch

php5 COM strange behaviour
        221150 by: Martin Staiger

Mac OS X file name encoding problem
        221158 by: Giulio
        221159 by: Jasper Bryant-Greene

instanceof ...
        221160 by: Jochem Maas

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:


Kevin Waterson wrote:
> This one time, at band camp, Philip Hallstrom <phpphilip.pjkh.com> wrote:
>
>
>>My guess would be because file_get_contents returns the contents as a
>>string. So if 'myfile' is 100mb, you're going to have to allocate 100mb
>>of memory to store that string while echo() spits it back out.
>>
>>But I'm just guessing as I don't know for sure...
>
>
> I think you got it, we really dont have enough information on what he
> has in myfile.txt

readfile() is the correct function for this purpose. fpassthru() is
designed for if you need to seek to a particular point in the file and
then output the remainder (or do other voodoo with the file pointer
before outputting the contents), and file_get_contents() is for when you
need the file contents in a string.

However, the first comment on readfile() states that readfile() is 55%
slower than doing a simple loop until EOF and using fread(). I haven't
tested that claim, so YMMV.

Jasper

attached mail follows:


On Mon, August 22, 2005 12:30 pm, Evert | Rooftop wrote:
> I want to use a PHP script to pass through a file to the browser [
> right
> after some processing ].
> What is the fastest way to do this? I know
> echo(file_get_contents('myfile')); is not a good idea ;)

Actually, it's a Fine Idea *IF* the files are relatively small.

Except you don't need parens for "echo" since "echo" is not a
function, it's a language construct.

echo file_get_contents('myfile');

The extra parens you have are basically order of operation:
$x = (2 + 3) * 4
versus
$x = 2 + 3 * 4

so you've told PHP to do file_get_contents() FIRST and then, err,
there isn't anything else to do, really, so it's kinda silly... Like:

$x = (2 + 3);

> Is fpassthrough the right choice?

Only if you've already opened the file, and you maybe only want to
spit out the rest of the file after you skip the first part of the
file.

> maybe virtual, so it won't go through php but apache does the job?

Maybe... But that chews up another HTTP connection, I think...

> there's also readfile

Slightly better than echo file_get_contents(), but probably not much...

> Another question, how seriously does this affect the performance in
> comparison to let apache handle it. Is the difference big at MB+
> files?

If your files are *HUGE* you probably want to test on YOUR server with
fopen/fread-loop.

Depending on a bunch of factors, the size of the buffer you choose for
fread() could make a difference in the performance, I think.

readfile might still be faster, since it's all in C... Or it might
not, depending on what buffer size is buried in the C code for
readfile.

> or only significant when dealing with a lot of tiny files?

I suspect that for tiny files, it doesn't make much difference what
you use between echo get_file_contents()/readfile or even your own
fopen/fread loop. The overhead of the function call and opening up
the file, no matter who does it, is going to drawf the actual reading
of the contents.

TEST ON YOUR OWN SERVER IN LIFE-LIKE ENVIRONMENT

That's the only way you'll be sure all the answers here aren't full of
[bleep]

--
Like Music?
http://l-i-e.com/artists.htm

attached mail follows:


I'm using this method, works fine with 50mb+ files :

    if( $fd = fopen ($filepath, 'r')){
      while(!feof($fd)) {
        $buffer = fread($fd, 2048);
        print $buffer;
      }
      fclose ($fd);
      exit;
    }

Regards,
Kim Steinhaug
- - - - - - - - -
www.easycms.no

----- Original Message -----
From: "Evert | Rooftop" <evertrooftopsolutions.nl>
To: "PHP-Users" <php-generallists.php.net>
Sent: Monday, August 22, 2005 9:30 PM
Subject: [PHP] Files passing through

> Hi People,
>
> I want to use a PHP script to pass through a file to the browser [ right
> after some processing ].
> What is the fastest way to do this? I know
> echo(file_get_contents('myfile')); is not a good idea ;)
>
> Is fpassthrough the right choice?
> maybe virtual, so it won't go through php but apache does the job?
> there's also readfile
>
> Another question, how seriously does this affect the performance in
> comparison to let apache handle it. Is the difference big at MB+ files?
> or only significant when dealing with a lot of tiny files?
>
> Thanks for your help!
> Evert
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
>

attached mail follows:


Kim Steinhaug (php list) wrote:
> I'm using this method, works fine with 50mb+ files :
>
> if( $fd = fopen ($filepath, 'r')){
> while(!feof($fd)) {
> $buffer = fread($fd, 2048);
> print $buffer;
> }
> fclose ($fd);
> exit;
> }

Is there a reason why you assign the output of fread() to a variable and
then print it? Why not just:

print(fread($fd, 2048));

which would be faster because it doesn't need to assign to a variable,
wouldn't it? Maybe I'm missing something..

Jasper

attached mail follows:


On Tue, August 23, 2005 12:48 am, Jasper Bryant-Greene wrote:
> Kim Steinhaug (php list) wrote:
>> I'm using this method, works fine with 50mb+ files :
>>
>> if( $fd = fopen ($filepath, 'r')){
>> while(!feof($fd)) {
>> $buffer = fread($fd, 2048);
>> print $buffer;
>> }
>> fclose ($fd);
>> exit;
>> }
>
> Is there a reason why you assign the output of fread() to a variable
> and
> then print it? Why not just:
>
> print(fread($fd, 2048));
>
> which would be faster because it doesn't need to assign to a variable,
> wouldn't it? Maybe I'm missing something..

You're not missing anything, but a 2 K string buffer assignment/print
is probably not gonna save much...

Benchmark it both ways and see.

--
Like Music?
http://l-i-e.com/artists.htm

attached mail follows:


Richard Lynch wrote:
> On Tue, August 23, 2005 12:48 am, Jasper Bryant-Greene wrote:
>
>>Kim Steinhaug (php list) wrote:
>>
>>>I'm using this method, works fine with 50mb+ files :
>>>
>>> if( $fd = fopen ($filepath, 'r')){
>>> while(!feof($fd)) {
>>> $buffer = fread($fd, 2048);
>>> print $buffer;
>>> }
>>> fclose ($fd);
>>> exit;
>>> }
>>
>>Is there a reason why you assign the output of fread() to a variable
>>and
>>then print it? Why not just:
>>
>>print(fread($fd, 2048));
>>
>>which would be faster because it doesn't need to assign to a variable,
>>wouldn't it? Maybe I'm missing something..
>
>
> You're not missing anything, but a 2 K string buffer assignment/print
> is probably not gonna save much...
>
> Benchmark it both ways and see.

I benched this with a 100 MiB text file (largest I could find at short
notice). Buffer used for fread() calls was 2 KiB as above.

Values are averaged over 100 runs (I would have liked to do more, but I
don't have time). All values are to 4 significant figures.

Assigning to a variable and then printing took 0.5206 sec

Printing directly without assigning to any variable took 0.5178 sec

readfile() took 0.4632 sec

print(file_get_contents()) took 0.7037 sec

Therefore, readfile() is the fastest, print(file_get_contents()) most
definitely the slowest, and it makes ****-all difference between
assigning the buffer to a variable and not, at least for files around
100 MiB.

Jasper

attached mail follows:


I had a foreach loop working on an array as such:

$multiarray = array(array('person','person'),array('another','another'))

the array was put through

foreach($multiarray as $subArray){

do something with array

}

on each loop I would see $subArray= array([0] = 'person',[1] = 'person')
and then $subArray= array([0] = 'another',[1] = 'another')

In other cases person might have some other value in the [1] position.
(it is being used in a function to create a select statement).

After the upgrade from 4.3 to 4.4 though each iteration gives...

array([0] = array([0] = 'person', [1] = 'person'),[1] = 0) and
array([0] = array([0] = 'another', [1] = 'another'),[1] = 1)

I find it hard to believe that I must rewrite every foreach loop in my
application to adjust to this. After all everything I've read states
that the 4.4 release was just a bug and security fix release.

Has anyone seen this behaviour?

attached mail follows:


I found that the only way to get the function to behave is to add the
key...

foreach($multiarray as $key=>$subArray)

Now it displays as it previously did where $subArray is concerned. Is
there something I'm missing here? Was I the only person not using
"keys"?

On Mon, 2005-08-22 at 21:28, Larry Brown wrote:
> I had a foreach loop working on an array as such:
>
> $multiarray = array(array('person','person'),array('another','another'))
>
> the array was put through
>
> foreach($multiarray as $subArray){
>
> do something with array
>
> }
>
> on each loop I would see $subArray= array([0] = 'person',[1] = 'person')
> and then $subArray= array([0] = 'another',[1] = 'another')
>
> In other cases person might have some other value in the [1] position.
> (it is being used in a function to create a select statement).
>
> After the upgrade from 4.3 to 4.4 though each iteration gives...
>
> array([0] = array([0] = 'person', [1] = 'person'),[1] = 0) and
> array([0] = array([0] = 'another', [1] = 'another'),[1] = 1)
>
> I find it hard to believe that I must rewrite every foreach loop in my
> application to adjust to this. After all everything I've read states
> that the 4.4 release was just a bug and security fix release.
>
> Has anyone seen this behaviour?

attached mail follows:


-----Original Message-----
From: Larry Brown
To: php
Sent: 23/08/05 02:28
Subject: [PHP] foreach loop changed after 4.3 -> 4.4 upgrade

I had a foreach loop working on an array as such:

$multiarray = array(array('person','person'),array('another','another'))

the array was put through

foreach($multiarray as $subArray){

do something with array

}

on each loop I would see $subArray= array([0] = 'person',[1] = 'person')
and then $subArray= array([0] = 'another',[1] = 'another')

In other cases person might have some other value in the [1] position.
(it is being used in a function to create a select statement).

After the upgrade from 4.3 to 4.4 though each iteration gives...

array([0] = array([0] = 'person', [1] = 'person'),[1] = 0) and
array([0] = array([0] = 'another', [1] = 'another'),[1] = 1)

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

You have an out-of-date code optimizer insatalled -- install the latest
version of whichever one you are using. This is a known incompatibility --
a quick search in the bugs database would have found multiple entries about
it (see, for instance, http://bugs.php.net/bug.php?id=30914,
http://bugs.php.net/bug.php?id=31194, and at least a couple of dozen
others).

Cheers!

Mike

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

attached mail follows:


Hi,
I have a large string that I need to send to a script that creates an
image.
eg <img
src='createimage.php?wp=321,43,23,12,43,12,342,54,765,87,3,23,etc etc
etc
Until now this hasnt been a problem just putting the data in the URL,
but now Im faced with a string that is over 3000 characters....which
causes an issue and ends up displaying a red square on my page rather
than the nice data I requested. I cant seem to find a way around this,
someone else suggested posting the data, but how can I post from
HTML?...can anyone help with another solution?
Kind regards
Dean.
 

attached mail follows:


Dean Maunder wrote:
> Hi,
> I have a large string that I need to send to a script that creates an
> image.
> eg <img
> src='createimage.php?wp=321,43,23,12,43,12,342,54,765,87,3,23,etc etc
> etc
> Until now this hasnt been a problem just putting the data in the URL,
> but now Im faced with a string that is over 3000 characters....which
> causes an issue and ends up displaying a red square on my page rather
> than the nice data I requested. I cant seem to find a way around this,
> someone else suggested posting the data, but how can I post from
> HTML?...can anyone help with another solution?

You can't make a POST request for an image using the <img> tag.

What you could do, however, is put the data in a session variable and
access it in the createimage.php file.

Only thing I can think of, however, is that the createimage.php file
might be called by the browser before the calling page has finished
loading (esp. with newer pipelining browsers), and therefore before the
session vars are saved...

You could try it, though. Any other ideas?

Jasper

attached mail follows:


My session variables are saved in a database, that's more than possible,
tho the thought of saving a 3000char session variable in a table is a
bit hairy :)

-----Original Message-----
From: Jasper Bryant-Greene [mailto:jasperbryant-greene.name]
Sent: Tuesday, 23 August 2005 3:48 PM
To: php-generallists.php.net
Subject: Re: [PHP] Large URI request problem

>

You can't make a POST request for an image using the <img> tag.

What you could do, however, is put the data in a session variable and
access it in the createimage.php file.

Only thing I can think of, however, is that the createimage.php file
might be called by the browser before the calling page has finished
loading (esp. with newer pipelining browsers), and therefore before the
session vars are saved...

You could try it, though. Any other ideas?

Jasper

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

attached mail follows:


 
Just as a note, if I copy and paste the 'src' into my browser address
bar, the image works fine, it only seems to be when its used inside the
src tag.
Hmmmmmm....any ideas?

attached mail follows:


Dean Maunder wrote:
> My session variables are saved in a database, that's more than possible,
> tho the thought of saving a 3000char session variable in a table is a
> bit hairy :)

Wouldn't worry me. It's a lot better than putting it in the URL :)

The other thing I thought of is, how are you generating that list of
numbers in the calling script?

Couldn't whatever code you're using to get that list simply be moved to
the script that displays the image, with whatever information it needs
to find the right list passed to it? (I assume you're not passing the
same, or an equally long, list to the calling script in the URL...)

Jasper

attached mail follows:


 The list of numbers is generated by calling an xml file which
translates latitude and longitude into screen coordinates. This is done
from the main file because this is where I need to draw the map and
location points. The problem is in the createline.php which draws lines
between the location points. If I was to call the xml file again, its
going to slow things down quite considerably.

These suggestions are great tho, keep em commin :)

-----Original Message-----
From: Jasper Bryant-Greene [mailto:jasperbryant-greene.name]
Sent: Tuesday, 23 August 2005 4:44 PM
To: php-generallists.php.net
Subject: Re: [PHP] Large URI request problem

Dean Maunder wrote:
> My session variables are saved in a database, that's more than
> possible, tho the thought of saving a 3000char session variable in a
> table is a bit hairy :)

Wouldn't worry me. It's a lot better than putting it in the URL :)

The other thing I thought of is, how are you generating that list of
numbers in the calling script?

Couldn't whatever code you're using to get that list simply be moved to
the script that displays the image, with whatever information it needs
to find the right list passed to it? (I assume you're not passing the
same, or an equally long, list to the calling script in the URL...)

Jasper

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

attached mail follows:


On Mon, August 22, 2005 10:39 pm, Dean Maunder wrote:
> I have a large string that I need to send to a script that creates an
> image.
> eg <img
> src='createimage.php?wp=321,43,23,12,43,12,342,54,765,87,3,23,etc etc
> etc

Woof.

I'm surprised it took 3000 characters to become a problem... :-)

You MAY want to try your HTML with src="createimge.php?wp=..." instead
of the single quotes.

Yeah, HTML 4.0 or whatever didn't care, but that new-fangled XML HTML
crap it matters, I think.

> Until now this hasnt been a problem just putting the data in the URL,
> but now Im faced with a string that is over 3000 characters....which
> causes an issue and ends up displaying a red square on my page rather
> than the nice data I requested. I cant seem to find a way around
> this,
> someone else suggested posting the data, but how can I post from
> HTML?...can anyone help with another solution?

In the script that writes out the HTML, don't write out all those
numbers in the URL.

Stick them in a database table, or put them in a session, or if
speed/performance is a Big Issue, and those can't hack it, stick them
in Shared Memory.

http://php.net/shmop

Then you can pass a small identifier like an ID from the database, or
whatever you want for an array index in your $_SESSION, or a path and
integer for the shared memory.

If shmop isn't fast enough, then you're in real trouble :-)

--
Like Music?
http://l-i-e.com/artists.htm

attached mail follows:


On Mon, August 22, 2005 2:32 pm, Dan Trainor wrote:
> Would the abovementioned use of ForceType also allow one to produce an
> image given an HTTP GET query? I was tinkering around with something
> in
> the past where I wanted to implement something such as:
>
> <img src="http://example.com/myscript.php?site=1&image=2&something=3">
>
> Would what you suggest force the server to return an image for that
> given URL, so that the img src specification listed above will work?

Yes!!!

Sort of!

But not exactly that way.

See, if you do it with just the ForceType, it will work for MOST
browsers.

But the $_GET parameters will trip you up, on *some* minor browser
versions.

I think IE 4 on a Mac was one of them, for images... Or maybe that
was for PDFs... Whatever. The permutations of MS IE bugs in this
domain are endless.

Some stupid minor version of IE will *INSIST* that since your URL:
http://example.com/myscript.php?site=1&image=2&something=3
has no .jpg nor .jpeg in it, and it DOES have a .php in it, and it
uses GET parameters...

[voice-over voice="very small rocks" /]
Why, then, it *MUST* be a .php file !!!

Then, of course, IE says "I don't know what to do with a .php file!"

That version of IE will completely IGNORE your Content-type: header,
because Microsoft knows better.

After all, way back when, there were a lot of broken web-servers that
were not sending a Content-type at all, and the default is text/plain,
but the output was HTML and the URL had .htm in it, so Microsoft,
instead of correctly rendering broken web servers' documents as HTML
source, began getting "smart" about URLs and determined that the way
the URL looked was MUCH more important than that Standards-based
Content-type: header thingie. :-( :-( :-(

MS engineers continue down this false path, to this very day, so your
Content-type: image/jpeg is *IGNORED*, the GET parameters mean it
CANNOT be an image (in Microsoft's mind) because images are static,
and, why, if there's a .php in the URL, well then, it has to be a .php
document.

If you want your dynamic image to work in *EVERY* browser, do *NOT*
give the browser an opportunity to [bleep] up.

Make your URL look like this:
http://example.com/myscript/site=1/image=2/whatever=3/random=7564634/whatever.jpg

Put this in your .htaccess:
<Files myscript>
  ForceType application/x-httpd-php
</Files>

Use something like this (probably in an include file) to snag the
paramters that used to be in $_GET, but are now buried in the URL:
<?php
  $pathinfo = $_SERVER['PATH_INFO'];
  $parts = explode('/', $pathinfo);
  $PATH = '';
  while (list(, $part) = each($parts)){
    $keyvalue = explode('=', $part);
    switch (count($keyvalue)){
      case 0:
        # do nothing
      break;
      case 1:
        $PATH .= urldecode($keyvalue[0]);
      break;
      default:
        $key = $keyvalue[0];
        unset($keyvalue[0]);
        $value = implode('=', $keyvalue);
        $_PATH[$key] = urldecode($value);
      break;
    }
  }
                                                                                                                           ?>

You will now have $_PATH['site'] and so on.

$_PATH['random'] is being set simply to force the stupid IE browser to
not re-use the same image from its cache. Change the value randomly
every time you display the URL.

If you want to get really slick, you could use that rnskit (?) to make
$_PATH a superglobal just like $_GET. I ain't done that yet, but it's
on my "ToDo" list now.

Oh, and the 'whatever.jpg' will be in $PATH (no underscore) so you can
use that as a key to determine which filename to use as well.

Basically, your ForceType tells the web server that it *IS* a PHP
document, but the URL gives Microsoft no opportunity to figure out
that it's really a PHP script.

Since the site=1 is valid directory name, Microsoft has no choice but
to assume that is simply a directory where you store images.

It ends in 'whatever.jpg' so IE can ignore the Content-type header
(which it will) and it will "know" that the document is a JPEG.

If people right-click or if you use Content-type:
application/octet-stream, well, IE will "know" to use 'whatever.jpg'
in the "Save As..." box, because that's the name of the document.

Never mind that there is NO whatever.jpg anywhere on your server's
hard drive. :-)

In other words, if you want Microsoft Internet Explorer to work right,
you have to LIE to it. A lot.

Which is only fair, considering how much Microsoft lies to us. :-)

PS
This same technique, and indeed, that code to build $_PATH is also
crucial for dynamic PDFs, dynamic FDFs (and the PDFs embedded within
them), dynamic SWF (Ming), etc.

Microsoft IE has managed to screw all of these up, one way or another,
in various versions over the years.

You could waste a lot of time mapping out which versions of which IE
mess up what, but it's a LOT easier to just:

Make the URL "look" static -- No .php, no ?, and it ends with what
LOOKS like a static filename with the 3-letter extension MS uses to
determine document type.

Use ForceType to convert "script.php" to just "script"

Put a random number in all dynamic rich media (image, PDF, SWF, ...)
URLs so the IE cache won't work.

There was at least one weird bug in Netscape (4.7?) that this
technique also squashed.

More importantly, more recent versions of Mozilla/Firefox/Safari seem
to have actually started acting more like IE in this regard -- Using
the URL to determine Content-type instead of the Content-type header.

Why take chances? Why give the browser a chance to screw up? The
browser authors have proven themselves bug-ridden messes. Take
control. Make the URL something that no browser could possible screw
up and be done with it.

[/soapbox]

--
Like Music?
http://l-i-e.com/artists.htm

attached mail follows:


On Mon, August 22, 2005 12:56 pm, Chirantan Ghosh wrote:
> //////////////[snip]
>> You probably want to move into the relm of array's. For each one of
>> your
>> checkboxes, you can do this...
>>
>> <input type="checkbox" name="InterestedNumber[]"
>> value="1-877-HOMECASH">
> /////////////[/snip]
>
> I did look up ARRAY. I just didn't understand how I can insert a
> table(
> "InterestedNumber") in an arrey so I could put something like this for
> form
> processing:
> ------------------------------------------------------
> <?
> foreach($HTTP_GET_VARS as $indx => $value) {
> ${$indx}=$value;
> }
> foreach($HTTP_POST_VARS as $indx => $value) {
> ${$indx}=$value;
> }

Gak.

If you are going to do this, you might as well just turn
register_globals back "On"

You've got the SAME security problem -- You just are doing it to
yourself instead of letting PHP do it to you.

> if($sendmessage == "yes"){
>
> $mailBody .= "SelectedNumber: $SelectedNumber\n"; //////I am
> thinking this
> is where I should put the Array??/////

$mailBody .= "SelectedNumbers:\n";
$mailBody .= implode("\n", $InterestedNumbers);

> $mailBody .= "Comments: $comments\n\n\n";

--
Like Music?
http://l-i-e.com/artists.htm

attached mail follows:


On Mon, August 22, 2005 12:03 pm, Robert Cummings wrote:
> On Mon, 2005-08-22 at 14:16, Rick Emery wrote:
>>
>> "I read the following article and I wanted your feedback on it.
>> http://www.ukuug.org/events/linux2002/papers/html/php/#section_6. I

I only read half-way through it...

His first thesis (Section 2, after the Intro) that PHP's strength
comes from co-mingling HTML and business logic has some merit...

But, really, you can make a mess of that equally well in ANY language.

Only a disciplined architecture and design will stop that.

Section 3
Since this section is based on FACTUALLY INCORRECT statements, it's
utter bullshit.

Re-defining a function in PHP generates an error.

The PHP class system provides distinct name-spaces for functions (and
more)

His entire these is un-tenable.

Section 4
Again, FACTUALLY INCORRECT.

Virtually *all* of the settings can be over-ridden in .htaccess,
and/or in PHP code itself.

At this point, I quit reading. It's clear the author has NO CLUE
about how PHP actually works.

When a guy writes a document that is all anti-PHP that is FACTUALLY
INCORRECT, why would you bother to use it for anything at all?

PS There are also several typos in the document, which never helps.

--
Like Music?
http://l-i-e.com/artists.htm

attached mail follows:


On Mon, August 22, 2005 10:04 am, David Pollack wrote:
> I have a database with two tables. One is a table of events and the
> other is a table of locations. I'm creating a google map with the
> table of locations and would like to list the events at each place.
> I'm using mambo and the following query to get the data...
>
> $query2 = "SELECT #__places.*, #__events.title"
> . "\n FROM #__places, #__events"
> . "\n WHERE #__places.name = #__events.adresse_info"
> . "\n AND published='1'"
> . "\n ORDER BY ordering"
> ;
>
> $database->setQuery( $query2 );
> $rows = $database->loadObjectList();
>
> This returns the variable $rows with all the data I need to plot the
> points on the map and the titles of the events going on at each of
> these places. $rows is an array containing objects of each row of
> data. The problem I'm having is that some places have multiple events
> and when I plot the points, it'll plot multiple points for those
> places.

That may not be a problem, since the multiple points may simply
over-write each other, and you won't know the difference visually...

What I did in one similar situation, not yet finished, was to plot a
BIGGER dot (or whatever) when there were multiple "things" at one
point.

The more things, the bigger the dot.

You could even use ORDER BY (abs(lat) + abs(lng)) to get points "near"
each other to be sequential so that... [continued]

> What I'd like to do is collapse the array $rows so that when the name
> of a place is duplicated only the title of the event is added and not
> all the other duplicate info. I feel like this may be possible either
> through manipulation of the data in PHP or by using another sql query.
> Any help would be greatly appreciated.
>
> Here's some extra info in case you need it:
>
> // The call used to map all the points
> <?
> $j = 0;

$unique = array();

> foreach ($rows as $row) {

if (!isset($unique[$row->lng . '.' $row->lat])){

> ?>
>
> var html = createHTML("<? echo "$row->name"; ?>", "<? echo
> "$row->address"; ?>", "<? echo "$row->suburb"; ?>", "<? echo
> "$row->state"; ?>", "<? echo "$row->postcode"; ?>");
> var point = new GPoint(<? echo "$row->lng"; ?>,<? echo "$row->lat";
> ?>);
> var marker = createMarker(point, html);
> map.addOverlay(marker);
> <?
> if($sname == $row->name) {
> ?>
> marker.openInfoWindowHtml(html);
>
> <?

$unique[$row->lng . '.' . $row->lat] = true;
}

> }
> }
> ?>
>
> And here's the URL of the site

You could also do some basic arithmetic on the lng/lat and "cheat" the
dots over/up a bit if they are "too close" to a previously-used dot.

You may also want to consider trying to get each dot to have a number
($j leaps to mind) or something in the balloon image, so that you can
put corresponding numbers in the image and in the sidebar HTML so the
user can match up the map with the specials.

Otherwise, the connection between mapped points and drink specials is
too tenuous.

[continued]... and if you've used the ORDER BY suggested above, and
the bigger dots, you can have, EG, 5,6 in a balloon instead of just 5,
and then the nearby things will be listed together in an intuitive
way.

--
Like Music?
http://l-i-e.com/artists.htm

attached mail follows:


On Mon, August 22, 2005 8:13 am, Robin Vickery wrote:
> On 8/22/05, Richard Lynch <ceol-i-e.com> wrote:
>> On Sat, August 20, 2005 5:00 am, John Nichel wrote:
>> > Personally, I have never used \\ in PCRE when looking for things
>> like
>> > spaces (\s), word boundraries (\b), etc. and it's all worked out
>> fine.
>>
>> Personally, {
>> I
>> } have
>> never {
>> used
>> proper
>> indenting
>> in
>> my
>> code } and
>> it's
>> all
>> worked
>> out
>> fine;
>>
>> :-)
>
> Unnecessary backslashes make your regular expressions almost as
> unreadable as those indents.
>
> You only ever need to escape a backslash in single-quotes if it's
> before another backslash or a single-quote.
>
> In fact the manual itself explicitly says this:
>
> http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.single
>
> So what benefit exactly do you see in doubling up all the backslashes
> in a single-quoted regexp? It's certainly not helping readability, and
> they don't actually do anything...

The advantage that when I have to change the string to match the
new/altered data, and that data has, oh, I dunno, something like ' or
\ or 0, 1, 2, 3, ...9 in it, and then my Regex suddenly doesn't work
because \abc7 won't work the same as \7abc but \\abc7 works the same
as \\7abc

I have to MAINTAIN this code, and when the input changes, as it
inevitably will, I do *NOT* want to sit down and figure out that hairy
Regex again. It was bad enough the first time. Hell, I had to spend
a couple hours building it up iteratively to get it right.

If I use \\ when I want \, then it will ALWAYS be correct, no matter
what character I have to shove in after it to match "The New Data".

If I use \ when I want \, maybe it works sometimes, maybe it doesn't
when I have to match "the new data". (\t is tab)

I guess I just like things that ALWAYS work instead of things that
SOMETIMES work. Silly me.

\\ always works
\ only works sometimes, depending on what character follows it.

PS
A Regex is unreadable code by definition anyway.

\\ isn't any more unreadable, with practice, than \, especially if you
are CONSISTENT and use it in PHP all the time, not just in Regex.

But the sheer number of weird character combinations and positional
difference (^ inside [] and ^ outside [] and ^ at the beginning of
either are all COMPLETELY different) make Regex unreadable no matter
how long you stare at it.

I dunno what masochist invented this Regex crap, but he oughta be shot
:-)

* I actually LIKE Regex when it's simple... But, man, you start
adding in a lot of complexity, and it gets really ugly really fast.
Oh well. It works.

--
Like Music?
http://l-i-e.com/artists.htm

attached mail follows:


On 8/23/05, Richard Lynch <ceol-i-e.com> wrote:
> The advantage that when I have to change the string to match the
> new/altered data, and that data has, oh, I dunno, something like ' or
> \ or 0, 1, 2, 3, ...9 in it, and then my Regex suddenly doesn't work
> because \abc7 won't work the same as \7abc but \\abc7 works the same
> as \\7abc

Ummm... no it doesn't.

Both of these will fail to compile:
preg_match( '/\\7abc/', $myString);
preg_match( '/\7abc/', $myString);

Both of these are fine:
preg_match( '/\\abc7/', $myString);
preg_match( '/\abc7/', $myString);

In fact they behave *exactly* as if you hadn't doubled them up. You've
not achieved anything, but you've made your regexp just a little more
difficult to read and maintain.

> I guess I just like things that ALWAYS work instead of things that
> SOMETIMES work. Silly me.
>
> \\ always works
> \ only works sometimes, depending on what character follows it.

No it doesn't. Indiscriminately doubling up all your back-slashes is
not an alternative to actually learning the proper syntax.

> PS
> A Regex is unreadable code by definition anyway.
>
> \\ isn't any more unreadable, with practice, than \, especially if you
> are CONSISTENT and use it in PHP all the time, not just in Regex.

Yeah, "with practice" you can get used to anything... Unfortunately
I'm not the only developer here. There are three teams of programmers
who would take umbrage with any need to practice before reading my
code.

>
> But the sheer number of weird character combinations and positional
> difference (^ inside [] and ^ outside [] and ^ at the beginning of
> either are all COMPLETELY different) make Regex unreadable no matter
> how long you stare at it.

With practice...

No, you're absolutely right. The way operators change meaning
depending on context can be confusing, especially when you're getting
started. They're addressing this already with the design of Perl 6. No
doubt it'll trickle through to PHP in due course.

http://dev.perl.org/perl6/doc/design/apo/A05.html#Too_compact_and_"cute"

But in the mean time, it's not *that* hard to learn the syntax of
regular expressions. OK, they're rather terse. But apart from that,
they're a lot simpler than a proper language like PHP and you don't
seem to have problems with that.

> I dunno what masochist invented this Regex crap, but he oughta be shot

Computational Linguists, first up against the wall, come the revolution.

  -robin

attached mail follows:


Robin Vickery wrote:
> Both of these will fail to compile:
> preg_match( '/\\7abc/', $myString);
> preg_match( '/\7abc/', $myString);
>
> Both of these are fine:
> preg_match( '/\\abc7/', $myString);
> preg_match( '/\abc7/', $myString);
>
> In fact they behave *exactly* as if you hadn't doubled them up. You've
> not achieved anything, but you've made your regexp just a little more
> difficult to read and maintain.

You achieved something. You made your code syntactically correct, even
if PHP lets you get away with things like \a inside single-quoted strings.

>>\\ always works
>>\ only works sometimes, depending on what character follows it.
>
> No it doesn't. Indiscriminately doubling up all your back-slashes is
> not an alternative to actually learning the proper syntax.

The proper syntax is to double the backslash, not to rely on the fact
that the character following it happens to not make it a special character.

Jasper

attached mail follows:


On 8/23/05, Jasper Bryant-Greene <jasperbryant-greene.name> wrote:
> Robin Vickery wrote:
> > Both of these will fail to compile:
> > preg_match( '/\\7abc/', $myString);
> > preg_match( '/\7abc/', $myString);
> >
> > Both of these are fine:
> > preg_match( '/\\abc7/', $myString);
> > preg_match( '/\abc7/', $myString);
> >
> > In fact they behave *exactly* as if you hadn't doubled them up. You've
> > not achieved anything, but you've made your regexp just a little more
> > difficult to read and maintain.
>
> You achieved something. You made your code syntactically correct, even
> if PHP lets you get away with things like \a inside single-quoted strings.

They are both syntactically correct. Which is why you don't get a
syntax error for either of them.

As the manual explicitly says in section on single-quoted strings:
http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.single

"usually there is no need to escape the backslash itself."

"variables and escape sequences for special characters will not be
expanded when they occur in single quoted strings."

There's no need to invent syntactic rules just to make life difficult.

  -robin

attached mail follows:


On Mon, August 22, 2005 6:29 am, Jay Paulson wrote:
> I have a problem that I'm sure some of you have run into before,
> therefore I hope you all know of an easy solution. Some of my users
> are cutting and pasting text from Word into text fields that are being
> saved into a database then from that database being displayed on a web
> page. The problem occurs when some special characters are being used.
> Double quotes, single quotes, and other characters like accents etc
> have the special html code like &quote; etc replacing the special
> characters. What methods are being used to combat this issue? Is
> there a solution out there to run text through some sort of filter
> before submitting it to the database to look for these special
> characters and then replacing them?

You are not alone.

There are innumerable User Contributed notes in the on-line manual on
this topic, scattered through various function pages.

Some of them have some rather nice functions for finding and replacing
all the Microsoft crap with something that will work in all browsers.

I would recommend doing this before you insert to the database.

Yes, it's generally a Bad Idea to munge data before inserting, but in
this case, you will never, ever, ever want those nasty characters
again.

They have no meaning outside the context of MS Word, except, of
course, MS IE "embrace and extend" (cough, cough) will display them as
well, so all the MS Word, FrontPage, IE users tend to use them, not
realizing just how UGLY their site is for everybody else.

So unless you want to abandon all other browsers, and turn into a
Microsoft drone, you might as well replace them once, at insert, and
be done with it.

You don't need anything as fancy as a Regex, and the list of
characters has already been painstakingly built for you by people in
the User Contributed notes.

For that matter, they wrote the function you can copy/paste as well.

Here's the one I liked enough to steal:

  function un_microsuck($text){
    static $chars = array(
        128 => '&#8364;',
        130 => '&#8218;',
        131 => '&#402;',
        132 => '&#8222;',
        133 => '&#8230;',
        134 => '&#8224;',
        135 => '&#8225;',
        136 => '&#710;',
        137 => '&#8240;',
        138 => '&#352;',
        139 => '&#8249;',
        140 => '&#338;',
        142 => '&#381;',
        145 => '&#8216;',
        146 => '&#8217;',
        147 => '&#8220;',
        148 => '&#8221;',
        149 => '&#8226;',
        150 => '&#8211;',
        151 => '&#8212;',
        152 => '&#732;',
        153 => '&#8482;',
        154 => '&#353;',
        155 => '&#8250;',
        156 => '&#339;',
        158 => '&#382;',
        159 => '&#376;');
    $text = str_replace(array_map('chr', array_keys($chars)), $chars,
$text);
    return $text;
  }

That's not going to be TOO horribly slow unless you've got a TON of
data to run through.

Feel free to benchmark it and see.

I never have, since I'm only handling one or two INPUT fields from
copy/paste at a time by a site administrator.

If it's "too slow" you might be able to tweak it so the array_map()
result is cached in the function body to get a bit more speed out of
it.

Everything else from MS Word copy/paste can be handled by
htmlentities() upon OUTPUT to the browser.

You may need to re-name the function for inclusion in a day-job
corporate project/product... :-)

--
Like Music?
http://l-i-e.com/artists.htm

attached mail follows:


On Mon, August 22, 2005 3:48 am, Erik Gyepes wrote:
> Zachary Kessin wrote:
>
>> I am about to start on a project that seems like it would be right
>> for
>> a CMS system. It will be about 80% rather boring stuff with about
>> 20%
>> custom database work. I have looked at XOOPS and a few others.
>> However
>> I can not seem to find one rather important thing about XOOPS. I
>> understand how to use a module that someone else wrote, but I have
>> not
>> found any documentation on how to build my own blocks or application
>> components.
>>
>> I am not yet committed to XOOPS, so if there is different system
>> that
>> would be better that could work as well

There is a pretty cool site "out there" that lets you kick the tires
on a BUNCH of different PHP/MySQL CMS products/projects.

opencms.org or something like that.

I always have a tough time finding it with Google and whatnot, but
it's there.

Anyway, they basically installed a couple dozen CMS systems, and you
can set yourself up with your own sandbox install on THEIR server with
just a click of a button, then administer it and play with it, and
then they wipe it out in about 2 hours.

So you get a chance to play with it to see if you like each CMS, and
you've got 2 hours to check it out -- Or more, since you can start
over with a new sandbox. They just don't want you to try to run your
site through theirs.

I doubt that it will actually let you write/upload arbitrary PHP for
the missing 20%, but they MIGHT have some examples or user comments on
their site on these issues, and at least you can play with the 80% to
see if the features you need for that part are there.

HTH

--
Like Music?
http://l-i-e.com/artists.htm

attached mail follows:


You are referring to this page :
http://www.opensourcecms.com/

Regards,
Kim Steinhaug
- - - - - - - - - - - - -
http://www.easywebshop.no/

----- Original Message -----
From: "Richard Lynch" <ceol-i-e.com>
To: "Erik Gyepes" <erik.gyepesdepi.sk>
Cc: <php-generallists.php.net>
Sent: Tuesday, August 23, 2005 9:28 AM
Subject: Re: [PHP] Looking for CMS advice

> On Mon, August 22, 2005 3:48 am, Erik Gyepes wrote:
> > Zachary Kessin wrote:
> >
> >> I am about to start on a project that seems like it would be right
> >> for
> >> a CMS system. It will be about 80% rather boring stuff with about
> >> 20%
> >> custom database work. I have looked at XOOPS and a few others.
> >> However
> >> I can not seem to find one rather important thing about XOOPS. I
> >> understand how to use a module that someone else wrote, but I have
> >> not
> >> found any documentation on how to build my own blocks or application
> >> components.
> >>
> >> I am not yet committed to XOOPS, so if there is different system
> >> that
> >> would be better that could work as well
>
> There is a pretty cool site "out there" that lets you kick the tires
> on a BUNCH of different PHP/MySQL CMS products/projects.
>
> opencms.org or something like that.
>
> I always have a tough time finding it with Google and whatnot, but
> it's there.
>
> Anyway, they basically installed a couple dozen CMS systems, and you
> can set yourself up with your own sandbox install on THEIR server with
> just a click of a button, then administer it and play with it, and
> then they wipe it out in about 2 hours.
>
> So you get a chance to play with it to see if you like each CMS, and
> you've got 2 hours to check it out -- Or more, since you can start
> over with a new sandbox. They just don't want you to try to run your
> site through theirs.
>
> I doubt that it will actually let you write/upload arbitrary PHP for
> the missing 20%, but they MIGHT have some examples or user comments on
> their site on these issues, and at least you can play with the 80% to
> see if the features you need for that part are there.
>
> HTH
>
> --
> Like Music?
> http://l-i-e.com/artists.htm
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
>

attached mail follows:


> opencms.org or something like that.

It is http://www.opensourcecms.com/

Raz

attached mail follows:


On Mon, August 22, 2005 12:45 am, Andras Kende wrote:
> I have a some colorful pictures, Would like to add white text with
> black
> background around the white text...
>
> I can add the text fine but could figure out how to add black
> background..
>
>
> $textcolor = imagecolorallocate($destimg, 255, 255, 255);

$black = imagecolorallocate($destimg, 0, 0, 0);
imagefilledrectangle($destimg, 8, 8, 8 + 5 * strlen("test text"), 13,
$black);

> imagestring($destimg, 3, 10, 10, "test text", $textcolor);
> imagejpeg($destimg);

--
Like Music?
http://l-i-e.com/artists.htm

attached mail follows:


Hello NG,

we have a script to create a word-document via COM which, so far, run pretty
stable under php 4.3.7

Since we upgraded to php 5.0.3.3 the same script works only on the first
run!
On the following runs the same script causes a fatal error on the code
below:

Fatal error: Uncaught exception 'com_exception' with message 'Source:
Microsoft Word
Description: Wrong Parameter.' in [Scriptname]:65
Stack trace:
#0 [Scriptname](65): variant->GoTo('wdGoToField', 'wdGoToFirst', 1)
#1 [SourceScript] include('[Scriptname]')
#2 {main} thrown in [Scriptname] on line 65

Code :
================================================
$NumberFields = $word->ActiveDocument->MailMerge->fields->Count;
for ($CounterFields = 1; $CounterFields <= $NumberFields; $CounterFields++)
{
    $word->Selection->Range->GoTo(wdGoToField, wdGoToFirst, $CounterFields);
<-- Creates Fatal Error
   ...
}
================================================

When we reset the Apache-Service, the script runs again once! Subsequent
calls create the same fatal error again ... we changed access-rights in
dcomcnfg which didn't show any influence ...

Environment: win 2003 server, Apache 2.0.53

I'm greatful for any hint !

attached mail follows:


Hi all,

I have a problem with a script when it is runs on a Mac OS X
environment.

a part of this script simply takes an upoloaded temporary file and
writes it on the local system using ftp functions.

something like:

$filename = $TheNameToAssignToTheFile;
$ftps = ftp_connect($ftpaddress);
$ris = ftp_login($ftps,$ftpuser,$ftppassword);
$fi = fopen($_FILES['file']['tmp_name'],"rb");
ftp_fput($ftps,$filename,$fi,FTP_BINARY);
fclose($fi);

The problem appears when $filename contains special characters, like
accented chars, on Mac OS X the ftp_fput function returns me an error.

I thinked that the problem could depend on the filesystem encoding,
that on Mac OS X is Unicode, so I tryied this before:

$filename = utf8_encode($filename);

this way I have no more an error, but the file name of the uploaded
file results anyway corrupted with strange chars.

Any help is greatly appreciated,

         Giulio

attached mail follows:


Giulio wrote:
> I have a problem with a script when it is runs on a Mac OS X environment.
> [snip]
>
> The problem appears when $filename contains special characters, like
> accented chars, on Mac OS X the ftp_fput function returns me an error.
>
> I thinked that the problem could depend on the filesystem encoding,
> that on Mac OS X is Unicode, so I tryied this before:
>
> $filename = utf8_encode($filename);

Wouldn't it be utf8_decode(), since you're trying to go *from* a Unicode
filesystem (Mac OS X)?

Jasper

attached mail follows:


as of 5.1.1 instanceof will no longer call __autoload()
(which maybe implemented as a handler/function chain by then?)

Thank God/Angeline Jolie/My Cat/Other. :-)