[PHP] _SERVER["HTTP_ACCEPT_LANGUAGE"] en-us

2006-10-16 Thread John Taylor-Johnston


This is what http_accept_language gives me depending on which browser. 
Depending on the visitor in my region, it will either be French or English.


_SERVER["HTTP_ACCEPT_LANGUAGE"] en-us,en;q=0.8,fr;q=0.5,fr-ca;q=0.3
_SERVER["HTTP_ACCEPT_LANGUAGE"] fr-ca,en-us;q=0.5


Is this a reasonable approach?

if(stristr($_SERVER["HTTP_HOST"],"fr"))
{ include("french.htm");}else{ include("english.htm");}

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



Re: [PHP] A no brainer...

2006-10-16 Thread Larry Garfield
On Monday 16 October 2006 14:11, Richard Lynch wrote:

> I suspect that serialization overhead is trivial for scalar data, and
> only starts to kill you when one starts schlepping bloated OOP
> structures or arrays back and forth -- at which point you messed up
> your architecture, and the serialization performance is just a
> symptom, not the disease.

Yes, serialization is trivial for scalar data.  However, to use a real-world 
example, the Drupal CMS allows users to define an unlimited number of path 
aliases.  They're just key/value mappings, one string to another.  Any given 
page can have dozens of links on it, which means dozens of mappings.  The 
database table is really just a simple two column table, user path to system 
path.

In older versions, the system pulled the whole table out at once and built a 
look up array, once per page.  Only one query per page, but it meant a lot of 
data to pull and build.  On sites with lots of aliases, that got very slow.  
So the latest version now pulls records one at a time.  But that's a ton of 
SQL queries, many of which simply find no data in the first place.  So now 
there's talk of building the look up table one record at a time and caching 
that, but the serialization/deserialization costs there are non-trivial when 
you're talking about a large array.

The balance is still being worked out. :-)  I'm just pointing out that no 
matter how you slice it, there is no free lunch performance-wise when you 
need to store data.  The right balance will depend greatly on your use case.

-- 
Larry Garfield  AIM: LOLG42
[EMAIL PROTECTED]   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

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



Re: [PHP] A no brainer...

2006-10-16 Thread Ed Lazor


On Oct 16, 2006, at 6:20 PM, Roman Neuhauser wrote:
Modern filesystems cope well with large directories (plus it's  
quite

trivial to derive a directory hierarchy from the filenames).
Looking at the numbers produced by timing various operations in
a directory with exactly 100,000 files on sw RAID 1 (2 SATA disks)
in my desktop i'd say this concern is completely baseless.


I knew that you could get PHP to use a directory structure for the  
session data files, but hearing that you can have 100k files in a  
single directory and not run into performance issues or problems is  
news to me.  Which OS are you running?



It still uses  files, but hopefully you don't hit them very often,
especially when  you're dealing with the same table records.


A RDBMS is basically required to hit the disk with the data on
commit. One of the defining features of a RDBMS, Durability, says
that once you commit, the data is there no matter what. The  
host OS
may crash right after the commit has been acked, the data must  
stay.


You can turn on query caching in MySQL, but this will give you
*nothing* for purposes of session storage.


Unless session storage is used to save time in retrieving data,  
right?  I'm seeing your point on the writing, but what about reading?


I think it would be kind of fun to run some actual tests.




Also, having raw data is  always faster than having to process it
before you can use it.


I don't know what that means.


If you pull a record from the db, you can access the data.  Or you  
can query the db, get the serialized data, de-serialize it, and now  
access the data.




Bytes in files on disk are as raw
as it gets, you get one roundtrip process -> kernel -> process;
compare the communication protocol MySQL (or just any other DB)  
uses

where data is marshalled by the client, and unmarshalled by the
server, overhead of the database process(es) taking part in the
write...

So no, it makes no sense for a database to be faster than
filesystem.


I tested this previously and found the database to be faster.  The  
references I gave supported this and listed additional benefits.   
Things change tho, especially with technology.  It seems like we  
should be able to test this pretty easily.  I actually think it would  
be fun to do as well.  Do you have a box we can test this on?   
Meanwhile, I'll check one of my boxes to see if I can use it.  If  
anything, it'll be interesting to see if two systems report the same.


-Ed

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



Re: [PHP] A no brainer...

2006-10-16 Thread Roman Neuhauser
# [EMAIL PROTECTED] / 2006-10-15 16:54:29 -0700:
> 
> On Oct 15, 2006, at 3:27 PM, Tony Di Croce wrote:
> 
> >Wow... well, I was certainly not speaking from direct experience,  
> >only from what seemed to make sense to me. This tells me that their  
> >is some serious room for improvement in PHP de-serialization code...
> 
> Well, kinda.  Hard disks are a lot slower than ram and that gives  
> file storage a disadvantage.  You can setup disk caching to help, but  
> the OS still starts to lag when you have a lot of files in one  
> directory, which is what happens with session data files.

Modern filesystems cope well with large directories (plus it's quite
trivial to derive a directory hierarchy from the filenames).
Looking at the numbers produced by timing various operations in
a directory with exactly 100,000 files on sw RAID 1 (2 SATA disks)
in my desktop i'd say this concern is completely baseless.

> MySQL  tries to cache data in memory as much as possible.

It cannot (MUST NOT) cache writes.

> It still uses  files, but hopefully you don't hit them very often,
> especially when  you're dealing with the same table records.

A RDBMS is basically required to hit the disk with the data on
commit. One of the defining features of a RDBMS, Durability, says
that once you commit, the data is there no matter what. The host OS
may crash right after the commit has been acked, the data must stay.

You can turn on query caching in MySQL, but this will give you
*nothing* for purposes of session storage.

> Also, having raw data is  always faster than having to process it
> before you can use it.

I don't know what that means. Bytes in files on disk are as raw
as it gets, you get one roundtrip process -> kernel -> process;
compare the communication protocol MySQL (or just any other DB) uses
where data is marshalled by the client, and unmarshalled by the
server, overhead of the database process(es) taking part in the
write...

So no, it makes no sense for a database to be faster than
filesystem.

-- 
How many Vietnam vets does it take to screw in a light bulb?
You don't know, man.  You don't KNOW.
Cause you weren't THERE. http://bash.org/?255991

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



Re: [PHP] A no brainer...

2006-10-16 Thread Ed Lazor


On Oct 16, 2006, at 1:03 PM, Richard Lynch wrote:

My thesis is that choosing SOLELY on raw performance without regard to
security, scalability is silly, and it's particularly silly on sites
that get so little traffic that "raw performance" tests and benchmarks
are rendered meaningless.


I that case, I agree with you whole heartedly.  Security and  
scalability are definitely important.



Yeah, sure, in a shared hosting environment, a really bad script can
be problematic -- I know, cuz I've gotten those emails from my webhost
:-)


So you're the one! ;) hehe

-Ed

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



Re: [PHP] Windows ENV['_'] equivalent

2006-10-16 Thread Stut

Richard Lynch wrote:

On Sat, October 14, 2006 4:09 am, Stut wrote:

Richard: AFAIK there is no way to know this under windows without
writing an extension to tell you.


Sounds like you actually know how to do this... :-)

Would such an extension be cross-platform to all PHP installs, or
Windows-only?

And is this some trivial thing that the PHP Devs just havent' had time
to do, or some monumental task of goofy OSes that nobody wants to
touch?

I'm happy to take a shot at it if it's easy, but if it's something the
PHP Devs don't want to touch, I know I ain't got a shot at it! :-)


I've not looked at the CLI SAPI at all yet, so I don't know if it gets 
put anywhere, but the SAPI main() function will get what you want passed 
to it. I guess now's as good a time as any...


Hey, whaddya know, it does. Check out [1]. Not sure how you'd get to 
that in an extension, but it's there. Since it's not linked that's a 
pretty good sign that that particular member of the struct is not used 
anywhere. In fact, looking at the usage of that var [2] it may not be 
available outside the SAPI code.


However, looking a bit further [3] it's defined as a static var in 
php_cli.c, so you may be able to get at it with an extern declaration. 
You should get the full path to the binary from the CLI module, looks 
like it's NULL for any SAPI that doesn't set it. However, it was never 
going to be that simple. It looks like that struct has a different name 
in each SAPI, so you may need to do something to mod the code if it's 
not building the CLI SAPI.


Should be able to knock something up armed with that. And yes, it should 
be the same code for all platforms. I'd love to have a go at this myself 
(just for fun), but unfortunately I don't have a great deal of spare 
time at the moment. Let me know how you get on.


[1] http://lxr.php.net/source/php-src/sapi/cli/php_cli.c#691
[2] http://lxr.php.net/ident?i=cli_sapi_module
[3] http://lxr.php.net/source/php-src/sapi/cli/php_cli.c#368

-Stut

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



RE: [PHP] Regular expressions

2006-10-16 Thread Chrome
>On 10/16/06, Chrome <[EMAIL PROTECTED]> wrote:
>> [snip]
>> ? means "maybe" in some other place in PCRE.  Or maybe that's POSIX.
>> Never have figured that one out.
>> [/snip]
>>
>> ? directly after an expression is equivalent to {0,1} (maybe) but
>> after a quantifier (*, +, {}) means ungreedy
>
>I kind of talked about this in the reply to richard the .*? is exactly
>the same as doing .*(?U)
>
>an inline modifier to the previous expression.
>
>That makes me wonder.. according to the docs U inverts greediness, if
>you have...
>/foo.*?bar/U
>
>does that make .*? a greedy .*
>
>Curt.

Good point... I suppose it would... I'm not au fait with greediness in
honesty... I just remember the syntax

Strange really because I'm arguing with a regex at the minute lol

Dan

-- 
http://chrome.me.uk

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



Re: [PHP] Retrieving values from array on a class

2006-10-16 Thread Stut

Richard Lynch wrote:

But I don't think you can even *DO* an include() inside a class
definition, so that should be giving you an error...


You can do an include/require anywhere. However, you cannot declare new 
functions inside an include and use it to add methods or variables to a 
class.


-->--inc.php-->--
--use.php-->--
foo(); // This will not work
print foo(); // But this will
--<---<--

This will not work! foo() is actually defined at the global scope.

-Stut

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



Re: [PHP] Regular expressions

2006-10-16 Thread Curt Zirzow

On 10/16/06, Chrome <[EMAIL PROTECTED]> wrote:

[snip]
? means "maybe" in some other place in PCRE.  Or maybe that's POSIX.
Never have figured that one out.
[/snip]

? directly after an expression is equivalent to {0,1} (maybe) but after a
quantifier (*, +, {}) means ungreedy


I kind of talked about this in the reply to richard the .*? is exactly
the same as doing .*(?U)

an inline modifier to the previous expression.

That makes me wonder.. according to the docs U inverts greediness, if
you have...
/foo.*?bar/U

does that make .*? a greedy .*

Curt.

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



Re: [PHP] Regular expressions

2006-10-16 Thread Curt Zirzow

On 10/16/06, Richard Lynch <[EMAIL PROTECTED]> wrote:

On Mon, October 16, 2006 2:54 pm, Chrome wrote:
> *edit* sorry I didn't think and just hit reply on this instead of
> reply
> all... sorry Richard */edit*
>
> [snip]
> .*? is kinda silly -- .* mean "0 or more characters", and ? means
> "maybe"
> but putting them together has no added value, so lose the ?
> [/snip]
>
> I could be wrong (and under the considerable knowledge of Richard I
> certainly feel it :) ) but doesn't the ? after a quantifier signify
> that
> preceding pattern is to be taken as ungreedy?

You're right; I'm wrong.

I'm not PCRE expert.

Took me 20 years to be able to stumble through the simplest expressions.

? means "maybe" in some other place in PCRE.  Or maybe that's POSIX.
Never have figured that one out.


The ? after * means ungreedy only.. so your basic:
 a? means a or no a in the regular usage

The easiest to remember is that ? two basic definitions:
 - extend the meaning of
 - 0 or 1 of the previous expression



/foo(?i)bar/

matches FOoBar, fOObar, foobar.. the (?i) extends the meaning of
(?[modifer-list])  to contain modifiers of the previous expression and
no more

/foo.*?bar/
 is the same thing as saying /foo.*(?U)bar; a short cut, much like
what \d is a shortcut to [0-9]

/foo(?<)/
 a look behind assertion

/foo(?=...)/
 a look ahead assertion

(and a negative of the  assertions are allowed)

/foo(?(condition)yes:no)/
 condition usually being an assoertion of some sort


I still dont understand it, and it is one of the reasons why people
have problems using regex, it really is a whole different language,
using Regex Coach as chrome did, is the probably the best way to find
out the problem or how to match what you are looking for...

A nice little overview (although i have read it about a few dozen
times and still cant apply the logic 100% of the time)
php.net/reference.pcre.pattern.syntax.php

on the other hand, people still want html parsers written in PCRE.. :)


Curt.

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



Re: [PHP] Regular expressions

2006-10-16 Thread Morten Twellmann
Great! It works! Thank you very much.

Also thanks to all the other guys who answered. I also think I finally
started to understand these regular expressions a bit better.

- Morten

- Original Message - 
From: "Richard Lynch" <[EMAIL PROTECTED]>
To: "Morten Twellmann" <[EMAIL PROTECTED]>
Cc: 
Sent: Monday, October 16, 2006 7:42 PM
Subject: Re: [PHP] Regular expressions


> On Sat, October 14, 2006 4:19 pm, Morten Twellmann wrote:
> > I'm trying to understand these regular expressions, but I can't make
> > them
> > work...
> >
> > All I want to do, is to find the first occurrence of some text inside
> > the
> > HTML tags  and .
> >
> > Example string: "October 14, 2006Welcome to my
> > homepageWe're happy to announce..."
> >
> > must return:
> >
> > "Welcome to my homepage"
> >
> >
> > I tried with:
> >
> > preg_match(']*>(.*?)', "Welcome to my homepage",
> > $matches, PREG_OFFSET_CAPTURE);
> > print_r($matches);
> >
> > but got nothing...
> >
> > Can anyone tell me how to do this?
> >
> > (I tried the above expression in EditPad Pro 6 and it worked...!)
>
> Download "The Regex Coach" and play with that -- It's not 100% the
> same as PHP, and the escaping of backslashes for PHP isn't in it, but
> it rocks for visual presentation of pattern/match
>
> Your main problem is a lack of start/end delimiters for the pattern:
> '|]*>(.*)|ims'
> would probably be better.
> | at beginning/end as pattern delimiters
> i becase H1 and h1 are both the same tag in HTML
> ms because newlines inside the text are okay
> Take out the \b because I dunno what it does, but you don't need it.
> .*? is kinda silly -- .* mean "0 or more characters", and ? means
> "maybe" but putting them together has no added value, so lose the ?
>
> -- 
> Some people have a "gift" link here.
> Know what I want?
> I want you to buy a CD from some starving artist.
> http://cdbaby.com/browse/from/lynch
> Yeah, I get a buck. So?
>
>

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



RE: [PHP] Regular expressions

2006-10-16 Thread Chrome
[snip]
? means "maybe" in some other place in PCRE.  Or maybe that's POSIX. 
Never have figured that one out.
[/snip]

? directly after an expression is equivalent to {0,1} (maybe) but after a
quantifier (*, +, {}) means ungreedy

I'm sure I'll be corrected if I'm wrong :)

Dan

-- 
http://chrome.me.uk

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



Re: [PHP] Windows ENV['_'] equivalent

2006-10-16 Thread Richard Lynch
On Mon, October 16, 2006 4:41 pm, Roman Neuhauser wrote:
> Just a thought: var_dump(ini_get('register_argc_argv')) ?

I should have been more clear

If/when there are any $args, then $argc/$argv are set:
$ /cygdrive/c/php5.1.1/php.exe -q argv.php
array(1) {
  [0]=>
  string(8) "argv.php"
}

C:\Documents and Settings\rlynch>c:\php5.1.1\php.exe -q
K:\pizzahut\argv.php
array(1) {
  [0]=>
  string(20) "K:\pizzahut\argv.php"
}

But $argv does not contain the path of the binary PHP running -- it
has everything AFTER that in the command line.

-- 
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

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



Re: [PHP] Regular expressions

2006-10-16 Thread Richard Lynch
On Mon, October 16, 2006 2:54 pm, Chrome wrote:
> *edit* sorry I didn't think and just hit reply on this instead of
> reply
> all... sorry Richard */edit*
>
> [snip]
> .*? is kinda silly -- .* mean "0 or more characters", and ? means
> "maybe"
> but putting them together has no added value, so lose the ?
> [/snip]
>
> I could be wrong (and under the considerable knowledge of Richard I
> certainly feel it :) ) but doesn't the ? after a quantifier signify
> that
> preceding pattern is to be taken as ungreedy?

You're right; I'm wrong.

I'm not PCRE expert.

Took me 20 years to be able to stumble through the simplest expressions.

? means "maybe" in some other place in PCRE.  Or maybe that's POSIX. 
Never have figured that one out.

-- 
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

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



[PHP] Dansie / ZenCart authorizenet Help

2006-10-16 Thread Richard Lynch
Trying to wrap up a PHP project, and am stumped by some not very PHP
issues...

I need some help with the following scenario:

Dansie shopping cart (Perl) is in use, and must remain active until
other "stores" can be re-coded.
ZenCart is installed, and ready to roll, except...
Setting in authorizenet control panel are making it not work.
Using a fresh new dev account can test/production ZC transactions fine.
I'm trying to use authorizenet_aim module.
Dansie is definitely not using _aim.
Talking to authorizenet has been a brick wall so far.

So somebody who REALLY understands authorizenet and all their control
panel things that make no sense to me is needed.

The client has signed a rather large contract that stepped up
development pace from "whenever" to "yesterday"...

The carrot:

Much future PHP work may be available with this client, as I'm way too
busy to do things at their pace/needs.

Rates negotiable.

Please reply off-list, of course.

-- 
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

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



Re: [PHP] Regular expressions

2006-10-16 Thread Curt Zirzow

On 10/16/06, Chrome <[EMAIL PROTECTED]> wrote:

*edit* sorry I didn't think and just hit reply on this instead of reply
all... sorry Richard */edit*

[snip]
.*? is kinda silly -- .* mean "0 or more characters", and ? means "maybe"
but putting them together has no added value, so lose the ?
[/snip]

I could be wrong (and under the considerable knowledge of Richard I
certainly feel it :) ) but doesn't the ? after a quantifier signify that
preceding pattern is to be taken as ungreedy?


Yes, this is correct. ? after * means means  ungreedy in this paticular match.


Curt.

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



Re: [PHP] A no brainer...

2006-10-16 Thread Richard Lynch
On Mon, October 16, 2006 2:44 pm, Ed Lazor wrote:
>> Almost ALL of this is moot for any but the hardest-hit sites -- So
>> choosing your session store based solely on performance for a
>> boutique
>> store is just plain silly.
>
> You don't have to be one of the hardest-hit sites to benefit.  I
> won't go so far as to say that all sites benefit, but even the
> boutique benefits, if you're running multiple sites on one server,
> which is common.  I agree with the other stuff you said about
> serialization :)

My thesis is that choosing SOLELY on raw performance without regard to
security, scalability is silly, and it's particularly silly on sites
that get so little traffic that "raw performance" tests and benchmarks
are rendered meaningless.

E.g., I don't really CARE what happens when you run my shopping cart
code 1 billion times, because it's not going to be run 1 billion times
in its entire life-cycle :-)  I want code I can maintain and not have
to wrap my brain into a pretzel to change the price of a product.

Yeah, sure, in a shared hosting environment, a really bad script can
be problematic -- I know, cuz I've gotten those emails from my webhost
:-)
[not about a shopping cart, but about incorrectly-optimized geo-search
queries, actually -- fixed.]

-- 
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

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



Re: [PHP] PHP Denial of service

2006-10-16 Thread Curt Zirzow

On 10/16/06, Richard Lynch <[EMAIL PROTECTED]> wrote:

On Fri, October 13, 2006 4:16 pm, Ryan Barclay wrote:
> A simple question I imagine, but I am wondering how I would combat DoS
> attacks by users holding the REFRESH key on their browsers?
>
> I have reproduced this error on a PHP-MYSQL website and when I hold
> the
> REFRESH key on for a while, page gen times shoot up dramatically and
> hundreds of processes are created.
>
> Is there a way I can stop this/limit the connections/processes in
> apache
> conf/php.ini?
>
> What can I do to combat this method of DoS?

Well, one thing for sure...

This question would be better addressed to Apache list.

To stay on topic, however, you could log each action the user takes,
and if they are "too fast" you can put a "sleep" call into your PHP
scripts.


ouch.. mabey a usleep() but that is a bad way to deal with things.
[getting off topic] that just makes it so you get all those requests
and apache grows closer to max_connections as ^R is hit.

[Back on topic or close]  if ^R forces the system to freeze up there
is something wrong somewhere.  For Starters... I doubt you can hit ^R,
or your client will allow ^R 200 times a second.. and i know of
systems that can handle 200 requests per second that use a db
connection via php without the server load going over 1.0.

At this point i think it is the magic eight ball that can only solve
this solution.. there are to many unknowns to really know what the
issue is.




This will only stop the user from doing what you did, not from a more
generalized DoS attack using something (slightly) more sophisticated
than the "refresh" button.


Yeah like requesting  from multiple machines all at the same time
multiple times. or would that be considered a DDoS?  if memory serves
me right, DoS is usually network flooding related vs trying to flood
processes handling.



So trying to solve this at the PHP level is most likely a Wrong Approach.


For true DoS, yeah very wrong place. i sort of have a feeling that
code/db/apache optimizations could occur before even considering DoS
things.

Curt.

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



Re: [PHP] Windows ENV['_'] equivalent

2006-10-16 Thread Richard Lynch
On Sat, October 14, 2006 4:09 am, Stut wrote:
> Richard: AFAIK there is no way to know this under windows without
> writing an extension to tell you.

Sounds like you actually know how to do this... :-)

Would such an extension be cross-platform to all PHP installs, or
Windows-only?

And is this some trivial thing that the PHP Devs just havent' had time
to do, or some monumental task of goofy OSes that nobody wants to
touch?

I'm happy to take a shot at it if it's easy, but if it's something the
PHP Devs don't want to touch, I know I ain't got a shot at it! :-)

-- 
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

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



Re: [PHP] Text from Excel csv file loaded into MySQL table

2006-10-16 Thread Richard Lynch
On Mon, October 16, 2006 11:01 am, Alan Milnes wrote:
> Chris Boget wrote:
>>> Can anyone point me to a really good end to
>>> end tutorial on extracting text from an Excel
>>> csv file and uploading it into MySQL via a
>>> PHP script?
>>
>> Actually, depending on the integrity of the data and the consistency
>> of
>> the format in the CSV file, you can do this simply and easily using
>> just
>> MySQL.  Take a look at the following pages:
>>
> Thanks for that.  As there will be a team of people creating the data
> and loading it I need to do some validation etc before it goes into
> the
> database.
>
> Currently I have this and it looks like it might work:-

Ah...

Try something like this:



This assumes that no record (all 4 fields) with overhead is move than
1Mb in size -- Change the 100 if you have monster fields.  And
count on needing to tweak my.cnf in that case anyway.

-- 
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

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



[PHP] Regular expressions

2006-10-16 Thread Chrome
*edit* sorry I didn't think and just hit reply on this instead of reply
all... sorry Richard */edit*

[snip]
.*? is kinda silly -- .* mean "0 or more characters", and ? means "maybe"
but putting them together has no added value, so lose the ?
[/snip]

I could be wrong (and under the considerable knowledge of Richard I
certainly feel it :) ) but doesn't the ? after a quantifier signify that
preceding pattern is to be taken as ungreedy?

The Regex Coach (which I use extensively) tends to agree

Just a thought...

Dan

PS. That isn't to say that Richards assessment of the regex is incorrect;
far from it
-- 
http://chrome.me.uk

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



Re: [PHP] Windows ENV['_'] equivalent

2006-10-16 Thread Richard Lynch
On Mon, October 16, 2006 9:04 am, Jochem Maas wrote:
> 2. try making use of the $_ENV['PHP_PEAR_PHP_BIN'] value which should
> be
> configured if pear is installed properly. (it's there in my local
> setup

C:\Documents and Settings\rlynch>C:\php5.1.1\php.exe -a
Interactive mode enabled



Notice: Undefined index:  PHP_PEAR_PHP_BIN in C:\Documents and
Settings\rlynch\- on line 1



C:\Documents and Settings\rlynch>


[EMAIL PROTECTED] /cygdrive/k/pizzahut/tests
$ /cygdrive/c//php5.1.1/php.exe  -a
Interactive mode enabled



Notice: Undefined index:  PHP_PEAR_PHP_BIN in k:\pizzahut\tests\- on
line 1


^D

[EMAIL PROTECTED] /cygdrive/k/pizzahut/tests



Apparently, PEAR is not correctly installed when I snag php5.1.1 and
dump it into c:\php5.1.1 and run CLI.  Since I seldom use PEAR, I've
never noticed this before.

I'm fairly confident that var_dump($_ENV) did not output any key/value
that had anything useful to my needs -- I scoured that pretty
carefully, as it's where I expected my answer to be.  Ditto for
$_SERVER.

-- 
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

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



Re: [PHP] PHP Denial of service

2006-10-16 Thread Curt Zirzow

On 10/14/06, Ryan Barclay <[EMAIL PROTECTED]> wrote:

It hasn't actually been attempted.  However, if a couple of a users were
to hold the refresh, the page generation times would go up ridiculously
and clients would be waiting over 20sec for pages.  As mentioned, it's a
very heavy php-mysql script with lots of queries.


A few questions:
#1: are those queries optimized (using indexes where needed)?
#2: is the code optimized.. no stupid loops.
#3: in order for php to know a user aborted it has to try to output
something (at least with apache on unix)

to deal with #3, i used to do a little trick:

?>

I dont know if that ?>http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] A no brainer...

2006-10-16 Thread Ed Lazor

Almost ALL of this is moot for any but the hardest-hit sites -- So
choosing your session store based solely on performance for a boutique
store is just plain silly.


You don't have to be one of the hardest-hit sites to benefit.  I  
won't go so far as to say that all sites benefit, but even the  
boutique benefits, if you're running multiple sites on one server,  
which is common.  I agree with the other stuff you said about  
serialization :)


-Ed

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



Re: [PHP] Windows ENV['_'] equivalent

2006-10-16 Thread Roman Neuhauser
# [EMAIL PROTECTED] / 2006-10-16 14:28:41 -0500:
> On Fri, October 13, 2006 7:44 pm, Roman Neuhauser wrote:
> > # [EMAIL PROTECTED] / 2006-10-13 13:53:56 -0500:
> >> So, I have this automated testing script I wrote, and I want to make
> >> it work on more than just my computer.
> >>
> >> In cygwin, and in Linux, EVN['_'] has the nice path to the binary
> >> CLI
> >> which is running -- which I call again in a backticks for each test
> >> script in turn, to provide a consistent starting point.
> >>
> >> In windows...  There ain't nothing in phpinfo() that matches the
> >> php.exe which I'm running...
> >>
> >> How do you handle this?
> >>
> >> Note that I'm not attempting to test specific versions of PHP --
> >> just
> >> the PHP scripts, so I really just want to run whatever PHP they are
> >> already running in their test environment, whatever that might be.
> >>
> >> It's not in $argv, it's not in ENV.
> >
> > What does $argv look like in windows?
> 
> $argv looks the same in both cases.
> 
> array (0) {
> }

Just a thought: var_dump(ini_get('register_argc_argv')) ?

-- 
How many Vietnam vets does it take to screw in a light bulb?
You don't know, man.  You don't KNOW.
Cause you weren't THERE. http://bash.org/?255991

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



Re: [PHP] mail() encoded subject line

2006-10-16 Thread Roman Neuhauser
# [EMAIL PROTECTED] / 2006-10-16 14:32:12 +0200:
> I hope this is not too off topic but I have a problem when I use mail(). 
> When I add the header Content-Type: text/plain; charset=UTF-8 the body 
> of the mail is encoded fine but the subject is not encoded. I've tried 
> to utf8_encode() and utf8_decode() the subject text but neither helps.
> 
> Any idea of how to pass what encoding to use on an email subject?

I see others already gave you some fish so I'll just offer you
the fishing manual: http://www.faqs.org/rfcs/rfc2047.html

-- 
How many Vietnam vets does it take to screw in a light bulb?
You don't know, man.  You don't KNOW.
Cause you weren't THERE. http://bash.org/?255991

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



Re: [PHP] Windows ENV['_'] equivalent

2006-10-16 Thread Richard Lynch
On Fri, October 13, 2006 8:14 pm, Ed Lazor wrote:
> Not a solution, but an idea...  the dos chdir comand.  Maybe you can
> run it from within your script. It tells you the current working
> directory and you end up indirectly knowing the location of the
> php.exe that you're using.

The test scripts live on a remote computer upon which I can't even run
an application like php.exe

The directory from which the other developers might choose to run the
test scripts is going to be typically idiosyncratic to their own dev
environment and drive mappings of remote shares.

I'm already pretty much forcing them to install php5 on their own
desktop/dev-box somewhere, if they don't already have it.

If they do have it, it could be anywhere.

-- 
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

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



Re: [PHP] Text from Excel csv file loaded into MySQL table

2006-10-16 Thread Alan Milnes

Chris Boget wrote:
Can anyone point me to a really good end to 
end tutorial on extracting text from an Excel 
csv file and uploading it into MySQL via a 
PHP script?  



Actually, depending on the integrity of the data and the consistency of
the format in the CSV file, you can do this simply and easily using just
MySQL.  Take a look at the following pages:
  
Thanks for that.  As there will be a team of people creating the data 
and loading it I need to do some validation etc before it goes into the 
database.


Currently I have this and it looks like it might work:-

# Open file
$fptr = fopen($filename, "r");

# Check if file is open
if($fptr) {
   $current_line = fgets($fptr,4096);

   $retval = TRUE;
   echo "open";
  
 while($current_line && $retval)

   {

$mystring=csv_string_to_array($current_line);

$query =
"insert into invw2wfinal
(
FIELD1,
FIELD2,
FIELD3,
FIELD4
  
)

values
(

'". mysql_real_escape_string($mystring[0]) ."',
'". mysql_real_escape_string($mystring[1]) ."',
'". mysql_real_escape_string($mystring[2]) ."',
'". mysql_real_escape_string($mystring[3]) ."'
)";

 $result = mysql_query($query);
 

   if(!$result)

   {
echo "Processing halted due to Error No:";
   echo mysql_errno().": ";
   echo mysql_error()."";
   echo "";
   $retval = FALSE;
   die;
   }
   elseif(mysql_affected_rows() == 0)
   {
 $retval = FALSE;
   die;
   }
 set_time_limit(0);
 $current_line = fgets($fptr,4096);
   }
} 


fclose($fptr);


function csv_string_to_array($str){

  $expr="/,(?=(?:[^\"]*\"[^\"]*\")*(?![^\"]*\"))/";

  $results=preg_split($expr,trim($str));

  return preg_replace("/^\"(.*)\"$/","$1",$results);

}

Alan

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



Re: [PHP] Windows ENV['_'] equivalent

2006-10-16 Thread Richard Lynch
On Fri, October 13, 2006 7:44 pm, Roman Neuhauser wrote:
> # [EMAIL PROTECTED] / 2006-10-13 13:53:56 -0500:
>> So, I have this automated testing script I wrote, and I want to make
>> it work on more than just my computer.
>>
>> In cygwin, and in Linux, EVN['_'] has the nice path to the binary
>> CLI
>> which is running -- which I call again in a backticks for each test
>> script in turn, to provide a consistent starting point.
>>
>> In windows...  There ain't nothing in phpinfo() that matches the
>> php.exe which I'm running...
>>
>> How do you handle this?
>>
>> Note that I'm not attempting to test specific versions of PHP --
>> just
>> the PHP scripts, so I really just want to run whatever PHP they are
>> already running in their test environment, whatever that might be.
>>
>> It's not in $argv, it's not in ENV.
>
> What does $argv look like in windows?

$argv looks the same in both cases.

array (0) {
}

-- 
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

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



Re: [PHP] Re: Windows ENV['_'] equivalent

2006-10-16 Thread Richard Lynch
On Fri, October 13, 2006 5:47 pm, M.Sokolewicz wrote:
> you've considered the fact that you might be running php as a module
> via
> ie. apache, thus not using a php.exe at all? (you'd be using a
> php4ts.lib/php5ts.lib instead)

It's a command line script having nothing to do with any other API.
CLI is definitely the SAPI here:

In Cygwin:
/cygwin/c/php5.1.1/php.exe -q run_tests.php
Cygwin gives me what I want in $_ENV['_']

In MS-DOS (errr, they don't call it that now, but it is):
C:\\php5.1.1\php.exe -q run_tests.php
MS-DOS does not have it anywhere I can find

I would think that the path to the binary being executed would be
available, but apparently not. [shrug]

I found one other solution, where a test suite defined its own ENV
variable that it expected the user to 'set' and then errored out if it
wasn't set...  This would not be my first choice for usability
reasons, as setting an ENV variable is actually rather tricky to
document:
If you are using bash, ... do this.
If you are using csh, ... do this.
If you are using Windows XP, ... do this.
If you are using Windows NT, ... do this.
If you are using any other platform, I have no idea what you would
have to do...

-- 
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

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



Re: [PHP] PHP Denial of service

2006-10-16 Thread Richard Lynch
On Fri, October 13, 2006 4:16 pm, Ryan Barclay wrote:
> A simple question I imagine, but I am wondering how I would combat DoS
> attacks by users holding the REFRESH key on their browsers?
>
> I have reproduced this error on a PHP-MYSQL website and when I hold
> the
> REFRESH key on for a while, page gen times shoot up dramatically and
> hundreds of processes are created.
>
> Is there a way I can stop this/limit the connections/processes in
> apache
> conf/php.ini?
>
> What can I do to combat this method of DoS?

Well, one thing for sure...

This question would be better addressed to Apache list.

To stay on topic, however, you could log each action the user takes,
and if they are "too fast" you can put a "sleep" call into your PHP
scripts.

This will only stop the user from doing what you did, not from a more
generalized DoS attack using something (slightly) more sophisticated
than the "refresh" button.

So trying to solve this at the PHP level is most likely a Wrong Approach.

-- 
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

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



Re: [PHP] A no brainer...

2006-10-16 Thread Richard Lynch
On Sat, October 14, 2006 5:57 pm, Ed Lazor wrote:
>
> On Oct 14, 2006, at 10:00 AM, Tony Di Croce wrote:
>
>> I think that the cost of de-serializing a session stored in files
>> should be significantly LESS than the cost of doing so through a
>> database, for the following reasons:
>>
>> 1) The db will need to parse querys. Not an issue for files.
>> 2) The session ID will tell PHP what file to open in O(1).
>> 3) The entire session needs to be de-serialized, not just some
>> portion of it. The database is optimized for returning subsets of
>> all the data.

As has been noted already, no blanket statement about peformance
should be blindly accepted -- Your hardware, your network, your app
framework (or lack thereof), your schema, etc. all affect that.

Not to mention any kind of fancy cache your DB might have going to
optimize queries versus your hard disk cache and how much data is
moving from A to B.

Almost ALL of this is moot for any but the hardest-hit sites -- So
choosing your session store based solely on performance for a boutique
store is just plain silly.

The de-serialization is also a red herring.  The data is serialized
independent of the storage mechanism.

Or, if ALL your data is scalar and needs no serialization, it looks
like you could NOT serialize/deserialize it and avoid the overhead, at
least in recent versions.  Might require changing PHP source in older
versions, but it's never been "impossible" :-)  Never tried this, but
it looks very do-able (and trivial) and could be fun.

You *might* even be able to write a custom serializer for your
specific data structures as a custom extension and significantly
improve on PHP's generalized approach.  Or not.  I dunno.  Try it and
see.

I suspect that serialization overhead is trivial for scalar data, and
only starts to kill you when one starts schlepping bloated OOP
structures or arrays back and forth -- at which point you messed up
your architecture, and the serialization performance is just a
symptom, not the disease.

YMMV

-- 
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

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



Re: [PHP] Retrieving values from array on a class

2006-10-16 Thread Roman Neuhauser
# [EMAIL PROTECTED] / 2006-10-16 12:47:47 -0500:
> On Sat, October 14, 2006 5:18 pm, Kevin Waterson wrote:
> >>>class returnConfigParams
> >>> {
> >>>
> >>>  var $a;
> 
> >>>  function getMySQLParams()
> >>>   {
> >>>include($_SERVER['DOCUMENT_ROOT']."/properties.php");
> >>>
> >>>$values = array(0 => $a, 1 => $b, 2 => $c, 3 => $d);
> 
> You probably want $this->a instead of $a
> 
> And that also assumes you are using $this->a inside of properties.php...
> 
> But I don't think you can even *DO* an include() inside a class
> definition, so that should be giving you an error...

You can include inside a function or method.

-- 
How many Vietnam vets does it take to screw in a light bulb?
You don't know, man.  You don't KNOW.
Cause you weren't THERE. http://bash.org/?255991

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



[PHP] Help, please! UTF-8 encoding problem

2006-10-16 Thread dimon
Hi,

I would like some help with an encoding problem, please. I would like to encode
some text (a news entry entered via a form, to be exact) into UTF-8 and then
save it in an XML file for persistent storage. My problem is, some of the users
are Japanese and would like to enter Japanese multi-byte characters. The
following should work, I believe:

// Open file
if (!$handle = fopen($filename, "wb")) {
echo("Error! Cannot open file $filename");
exit;
}

// Generate XML string
$newsXML = "\n";
$newsXML .= "\n";
$newsXML .= "".mb_convert_encoding($headline, "UTF-8");
$newsXML .= "\n";
$newsXML .= "".mb_convert_encoding($maintext, "UTF-8");
$newsXML .= "\n";
$newsXML .= "\n";

// Encode
$newsXML = mb_convert_encoding($newsXML, "UTF-8","auto");
$encodedNewsXML = utf8_encode($newsXML);
echo("".mb_detect_encoding($encodedNewsXML)."");
echo("".$encodedNewsXML."");

// Write news item content to the file
if (fwrite($handle, $encodedNewsXML) == FALSE) {
echo("Error! Could not write to file $filename");
exit;
}
echo("Success, wrote news item to the file $filename");
fclose($handle);



 ... but it doesn't! :-( Whenever I run this, it displays "ASCII" followed by
the Japanese text characters (both kanji and kana). Note that the caharcters
_are_ displayed correctly, although the encoding is detected as ASCII, which
doesn't make sense to me. The script then happily proceeds to save in
ASCII-format, and consequently, when the main script reads the saved file, it
replaces all characters by . Other UTF-8 files, saved in an external editor
such as Bluefish or GEdit _can_ be read correctly. The problem simply must be in
the encoding.

And before you ask, yes, mb_*** is supported in the PHP server.

What am I doing wrong? Please let me know; I've been struggling a long time with
this and will be very grateful for any assistance.

Best regards,
Jan


This message was sent using IMP, the Internet Messaging Program.

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



Re: [PHP] Class returning more than one value

2006-10-16 Thread Richard Lynch
On Sat, October 14, 2006 5:06 am, Deckard wrote:
> How can i code a class with a function that returns more than one
> value ?

Classes do not return values.

Functions return values.

Class methods (which are very much like functions) return values.

In PHP, functions/methods do not return more than one value.

You must wrap your multiple values up into some kind of more complex
(non-scalar) structure.

An array or an instance of a class will both work fine.

Which one is appropriate depends on the existing application,
framework, and personal religious convictions of code develoment.

YMMV

-- 
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

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



Re: [PHP] Crossing over to the Darkside?

2006-10-16 Thread Richard Lynch
On Sat, October 14, 2006 7:52 am, Ross wrote:
> I am very suprised how easy  things like user auhtentication and form
> validation is. Literally in minutes. Even though I have written a
> similar
> script many times for php there is always some tweeking or modifying
> required before it fits the project. The asp object model is far
> superior,
> something that PHP developers can't really argue against.

It makes the easy things easy, and the hard things harder. :-)

> -What is planned for the next version of PHP?

Google for "PHP 6 Roadmap"
Subscribe to php-internals or read its archives
There's no "secret" path of what's coming down the pike -- More like
wading through tons of arguments, actually. :-)

> -How many of  you use both of the technologies?

I used to use ASP -- Never again.
Okay, wait... Yeah, hand me $1,000,000 up-front as a signing bonus,
and I'll consider it.  This is not a joke.

> -What influences your decision when using either ASP, .NET, or PHP

If you want to do anything USEFUL in ASP or .NET, you can expect to
pay through the nose, or get nickel and dimed to death for things that
kinda sorta don't really work right, but they're cheap.

> I know people feel very strongly about PHP, however I don't want to
> start an
> argument, just want a decent discussion,

I'm not trying to be argumentative, though it probably sounds that way...

This is simply my real-world experience of ASP.

YMMV

-- 
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

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



Re: [PHP] Retrieving values from array on a class

2006-10-16 Thread Richard Lynch
On Sat, October 14, 2006 5:18 pm, Kevin Waterson wrote:
>>>class returnConfigParams
>>> {
>>>
>>>  var $a;

>>>  function getMySQLParams()
>>>   {
>>>include($_SERVER['DOCUMENT_ROOT']."/properties.php");
>>>
>>>$values = array(0 => $a, 1 => $b, 2 => $c, 3 => $d);

You probably want $this->a instead of $a

And that also assumes you are using $this->a inside of properties.php...

But I don't think you can even *DO* an include() inside a class
definition, so that should be giving you an error...

-- 
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

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



Re: [PHP] Retrieving values from array on a class

2006-10-16 Thread Richard Lynch
On Sat, October 14, 2006 9:55 am, AR wrote:
> $params_file = New returnConfigParams;
> $params_file->getMySQLParams();
> print($params_file[0]);
>
> but doesn't work :(
>
> Help me please.
>
> I'm stuck on this for two hours and didn't find nothing on Google that
> could help me.

There's nothing wrong with the above, but what's inside
getMySQLParams() function body?...

Use var_dump($params_file) to see what you've got so far.

And use var_dump($x) all through the function body to see what you're
doing -- where $x is any variable of interest at that line of code.

-- 
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

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



Re: [PHP] Regular expressions

2006-10-16 Thread Richard Lynch
On Sat, October 14, 2006 4:19 pm, Morten Twellmann wrote:
> I'm trying to understand these regular expressions, but I can't make
> them
> work...
>
> All I want to do, is to find the first occurrence of some text inside
> the
> HTML tags  and .
>
> Example string: "October 14, 2006Welcome to my
> homepageWe're happy to announce..."
>
> must return:
>
> "Welcome to my homepage"
>
>
> I tried with:
>
> preg_match(']*>(.*?)', "Welcome to my homepage",
> $matches, PREG_OFFSET_CAPTURE);
> print_r($matches);
>
> but got nothing...
>
> Can anyone tell me how to do this?
>
> (I tried the above expression in EditPad Pro 6 and it worked...!)

Download "The Regex Coach" and play with that -- It's not 100% the
same as PHP, and the escaping of backslashes for PHP isn't in it, but
it rocks for visual presentation of pattern/match

Your main problem is a lack of start/end delimiters for the pattern:
'|]*>(.*)|ims'
would probably be better.
| at beginning/end as pattern delimiters
i becase H1 and h1 are both the same tag in HTML
ms because newlines inside the text are okay
Take out the \b because I dunno what it does, but you don't need it.
.*? is kinda silly -- .* mean "0 or more characters", and ? means
"maybe" but putting them together has no added value, so lose the ?

-- 
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

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



Re: [PHP] Re: LAMP || Apache Cache PHP Source File...

2006-10-16 Thread Richard Lynch


Put it all in subversion and checkout on a regular basis?

On Sun, October 15, 2006 11:14 am, sit1way wrote:
> Hey All.
>
> Like many intermediate (and higher) level programmers, I've written a
> LAMP
> based CMS application to develop sites for my clients.
>
> Until recently I had major version control issues; i.e. when making a
> change/enhancement to one site, none of the other sites would get
> updated.
> Now I've got a source repository that stores the basic coding
> framework.
> Any new site that uses the CMS will draw on the source code base and,
> when
> applicable, draw on site specific custom class code to override source
> code
> defaults -- totally cool; now at long last, I truly have an
> application
> framework in place.
>
> The main concern I have now is that all sites will now draw on the
> same code
> base; more specifically, each site request for every site calls the
> CMS
> controller PHP script located in the source code repository (via
> Mod_Rewrite, Mod_Alias combo).  To speed up delivery of the source
> respository controller PHP script, I'd like to have Apache cache this
> file.
> Mod_File_Cache doesn't look like it will do the trick as this module
> only
> works with static content, and Mod_Cache seems to require a GET
> request,
> among other requirements, in order to perform file caching.
>
> If anyone has ideas, let me know!
>
> Thanks,
>
> --Noah
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


-- 
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

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



Re: [PHP] Setting PHP to use SMTP

2006-10-16 Thread Richard Lynch
On Sun, October 15, 2006 10:25 pm, Dave M G wrote:
> In an effort to make emails that I send through PHP scripts not be
> mistaken for spam, it seems that one thing I need to do is make sure
> that the emails are sent via SMTP.

I doubt that this is going to matter much...

The emails ALL end up going through SMTP sooner or later anyway.

It's a question of whether you re-invent the wheel to connect, use an
existing PHP package to connect, or use PHP to interface to an
existing non-PHP package to connect.

You'd only need to connect within PHP to SMTP for performance / volume
sending, not just making it look not like spam.

> Right now, if I check my PHP generated emails with Spamassassin, it
> says:
>
> -0.0 NO_RELAYS Informational: message was not relayed via SMTP

I think what it's REALLY saying is that the email went from your
server to itself, and did not bounce through a whole bunch of SMTP
relays along the way...

If you send the email to somebody else, it's gonna hit more SMTP
relays along the way.

If it's hitting a *lot* of SMTP relays, it's a sign that somebody is
forging the SMTP relay path to obscure their "trail" and they are a
spammer.

> It's not deducting points, but I think the fact that it mentions it
> indicates I might be better off using SMTP.

I don't think you are correctly interpreting the basic premise of
NO_RELAYS

> Looking at phpinfo, it says this about my PHP/SMTP settings:
>
> sendmail_from no value no value
> sendmail_path /usr/sbin/sendmail -t -i /usr/sbin/sendmail -t -i
> SMTP localhost localhost
>
> I take this to mean that I don't have a default "from" address, but
> that
> it knows where my SMTP server is.

You should have EITHER sendmail_path or SMTP set up, not both.

I don't even know what PHP is gonna do when you set up both...

What you've done is this:
"Here, use sendmail to send email.  Here, use SMTP to send email"

> However, the last variable, where it's set to "localhost", is not so
> clear to me. Does this mean PHP is using the SMTP server on localhost?
> Does this need to be changed in order for PHP to actually send via
> SMTP
> since it doesn't seem to be doing so now?

I think you'd need to turn off the sendmail_path.

But then don't be surprised if email doesn't go out at all if you
haven't configured SMTP on localhost to actually send/receive email.

And if you start doing that, make real sure you've locked it down so
you don't end up being an open relay and getting on everybody's
blacklist -- That will get you a zillion points deducted instead of
whatever miniscule SMTP bouncing count it's in the -0.0 you are
seeing.

> My virtual hosting service is the kind where I have two IP addresses,
> and I can add as many domain names as I want to my account. Does that
> mean that if I set a default email address in "sendmail_from" that it
> will apply to all my domains? Is there a way to localize the setting
> on
> a domain by domain basis? Or is this a question I need to take to my
> hosting service provider?

All depends how they are loading in php.ini and the PER_DIR/PER_INI
rules of the settings you want to change...

> And last... how exactly do I set the variables? Do I have to manually
> edit php.ini and then restart Apache? Is there a command I should be
> running?

php.ini is just a simple text file.

There are bound to be fancy editors for it, which may or may not be
useful to you.

You definitely need to restart apache, unless you are running as CGI
and then you don't.

Dislaimer: I'm not an SMTP/SpamAssassin expert by any stretch of the
imagination.

-- 
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

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



Re: [PHP] Solution: [PHP] OOP slow -- am I an idiot?

2006-10-16 Thread Roman Neuhauser
# [EMAIL PROTECTED] / 2006-10-15 13:59:39 -0700:
> As I cannot think of a class-based way to build my report, I think
> I'll use a customer class everywhere BUT in the report.  Inside the
> report I'll just use one SQL statement instead of dozens
> of instances and hundreds of queries.
> 
> I'll make a note inside the class that this and that method is not the
> only place the data is accessed, to also check inside the report.
> 
> Sometimes, you've just gotta compromise to get the job done.  Most of
> the time, OOP is a good idea, but in this instance I don't think it's
> the best choice.
 
You're suffering because you're putting code that belongs in
a separate layer (data source) in the domain logic layer.
Don't blame classes for shortcomings in your design.

http://www.martinfowler.com/articles/dblogic.html

-- 
How many Vietnam vets does it take to screw in a light bulb?
You don't know, man.  You don't KNOW.
Cause you weren't THERE. http://bash.org/?255991

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



Re: [PHP] Text from Excel csv file loaded into MySQL table

2006-10-16 Thread Richard Lynch
On Mon, October 16, 2006 10:40 am, Alan Milnes wrote:
> Can anyone point me to a really good end to end tutorial on extracting
> text from an Excel csv file and uploading it into MySQL via a PHP
> script?  There are lots of bits and pieces on the Web and in the PHP

If the files are NOT clean enough to do fgetcsv reliably, or you
suspect they might not be, you may want to consider putting together a
"preview" screen sort of like Excel does when you import data.

I did this once where it would also let the user re-assign various
columns in the data they were importing to the columns we were using,
since I know that they'd have more or less the same columns, mostly,
but did not know for sure where they'd be or what name they'd give
them.

It's a fair amount of work, but not super tricky or anything.

-- 
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

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



[PHP] mktime()'s is_dst deprecated, but needed?

2006-10-16 Thread Zora

Hi all,

(first time I send an email here, so please be forgiving if something 
doesn't follow expected rules.)


My web application allows users to enter time stamps (date and time) 
given as local times. The time stamp is to be stored as UTC into the 
data base.


Since we have summer and winter times (dst) there's an hour in the 
autumn which exists twice in local time (it's 2:00 - 3:00 at the last 
sunday in october here). Only the user knows which of these two hour is 
intended to be stored into the data base, no program ever can decide 
that by itself. Thus, the user has to add a character to the supplied 
time stamp.


E.g.
", 02:30 A" is summer time (e.g. GMT +02:00),
", 02:30 B" is winter time (e.g. GMT +01:00).

My php function used the "is_dst" parameter of mktime() responding to 
the user given "A" or "B".


How's that to solve in the future if "is_dst" doesn't exist any more?
(For now, it still works but gives a log line everytime the function is 
called - E_STRICT is set).


Thanks for your help,

Zora


RE: [PHP] Text from Excel csv file loaded into MySQL table

2006-10-16 Thread KermodeBear
Hello, 

> > Can anyone point me to a really good end to end tutorial on 
> extracting 
> > text from an Excel csv file and uploading it into MySQL via a PHP 
> > script?
> 
> Actually, depending on the integrity of the data and the 
> consistency of the format in the CSV file, you can do this 
> simply and easily using just MySQL.  Take a look at the 
> following pages:
> 
> MySQL >= 5.0
> http://dev.mysql.com/doc/refman/5.0/en/load-data.html
> 
> MySQL < 5.0
> http://dev.mysql.com/doc/refman/4.1/en/load-data.html

If the above is not an option for you, then use this:

http://us2.php.net/fgetcsv

Works like a charm.

-K. Bear

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



RE: [PHP] Text from Excel csv file loaded into MySQL table

2006-10-16 Thread Chris Boget
> Can anyone point me to a really good end to 
> end tutorial on extracting text from an Excel 
> csv file and uploading it into MySQL via a 
> PHP script?  

Actually, depending on the integrity of the data and the consistency of
the format in the CSV file, you can do this simply and easily using just
MySQL.  Take a look at the following pages:

MySQL >= 5.0
http://dev.mysql.com/doc/refman/5.0/en/load-data.html

MySQL < 5.0
http://dev.mysql.com/doc/refman/4.1/en/load-data.html

thnx,
Chris

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



[PHP] Text from Excel csv file loaded into MySQL table

2006-10-16 Thread Alan Milnes


Can anyone point me to a really good end to end tutorial on extracting 
text from an Excel csv file and uploading it into MySQL via a PHP 
script?  There are lots of bits and pieces on the Web and in the PHP 
manual but I haven't found a really comprehensive article yet. I have 
Welling and Thomson's book but again it's not detailed enough.


I've got a script at the moment which works fine with known values 
(generated by a program I own) but I now need to cater for files 
prepared by other people which may have all sorts of characters in them.


A typical line of text may look something like this:-

123456,99,Computer Systems,Desktops/Towers,HP,DX6100M,DX6100M,"127 
SHAWAK HARBAN, DUCK'S POINT",MUMBAI


I think I need to do something like this:-

Open the file
   Get the current line
   Convert it to an array (making sure I handle any commas etc in 
the user text)

   Map the array to the MySQL fields
   Upload it to the database, escaping as appropriate
Continue until all lines have been read.

I know I'm not the first person to have had to do this but can't find 
exactly what I'm looking for.


Thanks

Alan  


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



[PHP] Re: mail() encoded subject line

2006-10-16 Thread Manuel Lemos
Hello,

on 10/16/2006 02:32 PM Emil Edeholt said the following:
> I hope this is not too off topic but I have a problem when I use mail().
> When I add the header Content-Type: text/plain; charset=UTF-8 the body
> of the mail is encoded fine but the subject is not encoded. I've tried
> to utf8_encode() and utf8_decode() the subject text but neither helps.
> 
> Any idea of how to pass what encoding to use on an email subject?

Headers encoding is independent of message body encoding set by
Content-Type. Headers need to be encoded with q-encoding algorithm.

You may want to take a look at this popular MIME message class. Just use
the SetEncodedHeader function to add the Subject or another header that
may use 8 bit (non-ASCII) data.

The character set encoding of the message is set using the
default_charset class variable. But you can use a different character
set encoding for individual headers, using the 3rd parameter of the
SetEncodedHeader function.

Take a look at the test_email_message.php example script that shows how
to send messages with non-ASCII characters in the Subject and body.

http://www.phpclasses.org/mimemessage


-- 

Regards,
Manuel Lemos

Metastorage - Data object relational mapping layer generator
http://www.metastorage.net/

PHP Classes - Free ready to use OOP components written in PHP
http://www.phpclasses.org/

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



[PHP] Re: mail() encoded subject line

2006-10-16 Thread Colin Guthrie
Emil Edeholt wrote:
> Hi,
> 
> I hope this is not too off topic but I have a problem when I use mail().
> When I add the header Content-Type: text/plain; charset=UTF-8 the body
> of the mail is encoded fine but the subject is not encoded. I've tried
> to utf8_encode() and utf8_decode() the subject text but neither helps.
> 
> Any idea of how to pass what encoding to use on an email subject?
> 
> Thanks!
> 
> Regards Emil
> 

Have a look at the Zend Mail wrapper.

You have to specially encode the subject to be completely stand alone
from the encoding of the body. All header that contain special
characters (e.g. the From name) have to be stand-alone as the
Content-Type header only applies to the body of the message.

See here: http://www.snook.ca/archives/servers/encoding_accent/

In the Zend Framework:
http://framework.zend.com/fisheye/browse/~raw,r=598/Zend_Framework/trunk/library/Zend/Mail.php
Look at the _encodeHeader() function and more specifically the
Zend_Mime::encodeQuotedPrintable($value) method.

Hope that helps.

Col

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



Re: [PHP] Windows ENV['_'] equivalent

2006-10-16 Thread Jochem Maas
Richard Lynch wrote:
> So, I have this automated testing script I wrote, and I want to make
> it work on more than just my computer.
> 
> In cygwin, and in Linux, EVN['_'] has the nice path to the binary CLI
> which is running -- which I call again in a backticks for each test
> script in turn, to provide a consistent starting point.
> 
> In windows...  There ain't nothing in phpinfo() that matches the
> php.exe which I'm running...
> 
> How do you handle this?
> 
> Note that I'm not attempting to test specific versions of PHP -- just
> the PHP scripts, so I really just want to run whatever PHP they are
> already running in their test environment, whatever that might be.
> 
> It's not in $argv, it's not in ENV.
> 
> I've check the getmyinode() friends in PHP Options/Info page.
> 
> Surely Windows provides this info to PHP somewhere, and PHP exposes
> it, right?...  Guess not, hunh.
> 
> Anybody got a solution?

2 possible ideas:

1. use a wrapper script that allows you to specify which binary to run
the tests with. e.g. (my example suggests you would have a wrapper for
every version of php you wanted to test with)

> php5-1.bat runtests.php

php5-1.bat:
-
@echo off

:init_arg
set args=

:get_arg
shift
if "%0"=="" goto :finish_arg
set args=%args% %0
goto :get_arg
:finish_arg

set php=C:\path\to\php5.1.exe
set ini=C:\path\to\php5.1.ini
%php% -c %ini% -dPHP_VERSION=%php% %args%


2. try making use of the $_ENV['PHP_PEAR_PHP_BIN'] value which should be
configured if pear is installed properly. (it's there in my local setup


just some rough ideas, hope that one of them serves well enough to be
used as a workaround for the windows lack of functionality. good luck
(ps I'm very interested how you tackle the problem, looking forward to any
response)

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



[PHP] mail() encoded subject line

2006-10-16 Thread Emil Edeholt

Hi,

I hope this is not too off topic but I have a problem when I use mail(). 
When I add the header Content-Type: text/plain; charset=UTF-8 the body 
of the mail is encoded fine but the subject is not encoded. I've tried 
to utf8_encode() and utf8_decode() the subject text but neither helps.


Any idea of how to pass what encoding to use on an email subject?

Thanks!

Regards Emil

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



[PHP] connecting host.

2006-10-16 Thread Jo�o C�ndido de Souza Neto
I want to know if only i have connection problem with the server.

I cant count how many timnes a dey i get the message cannot connect to host 
news.php.net.

It happens to everyone ou just for me?

Thanks.

-- 
João Cândido de Souza Neto
Curitiba Online
[EMAIL PROTECTED]
(41) 3324-2294 (41) 9985-6894
http://www.curitibaonline.com.br 

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



Re: [PHP] Re: Setting PHP to use SMTP

2006-10-16 Thread Chris

Dave M G wrote:

David,

Thank you for your response.


If you are on *nix and want to send mail via SMTP, you need something 
like
http://phpmailer.sourceforge.net/ 
I have looked at phpmailer, but it's way over featured for what I want 
to accomplish. The tutorial they link to on their site, 11 pages long 
and full of settings I don't need, really turns me off.


Is there no way to simply force my PHP emails through SMTP? I'm happy 
about everything else with my email set up, so surely there's a way to 
handle this one thing.


It's not simple.

Basically you need to:
- open a socket
- send commands through
- check that worked
- check *each* response that comes back
- make sure it's a valid response (from the smtp server)
- send more data

rinse, repeat.

There are tons of checks you need to do at each step and getting the 
format of the email, headers and commands right is painful (and even 
then it can break depending on the type of server you're going to send 
through - windows servers are slightly different to *nix servers even 
though they are both supposed to be rfc compliant).



If you really want to do it yourself, the easiest way would be to look 
at how phpmailer or something like it handles the process - turn debug 
on (I'm sure the docs mention how to do this) and watch the commands fly 
(and there are a lot of commands).


My code to do all of that is over 400 lines (but does include debug 
statements) - and that's just to send a message through the smtp server 
(connect, send the necessary commands, check return codes and so on).


--
Postgresql & php tutorials
http://www.designmagick.com/

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



Re: [PHP] Re: Setting PHP to use SMTP

2006-10-16 Thread Dave M G

David,

Thank you for your response.


If you are on *nix and want to send mail via SMTP, you need something like
http://phpmailer.sourceforge.net/ 
I have looked at phpmailer, but it's way over featured for what I want 
to accomplish. The tutorial they link to on their site, 11 pages long 
and full of settings I don't need, really turns me off.


Is there no way to simply force my PHP emails through SMTP? I'm happy 
about everything else with my email set up, so surely there's a way to 
handle this one thing.


--
Dave M G
Ubuntu 6.06 LTS
Kernel 2.6.17.7
Pentium D Dual Core Processor
PHP 5, MySQL 5, Apache 2

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