Re: [PHP] phpsadness

2011-06-03 Thread Peter Lind
On Jun 3, 2011 3:48 PM, tedd tedd.sperl...@gmail.com wrote:

 At 1:02 PM -0400 6/2/11, Daniel Brown wrote:

 On Tue, May 31, 2011 at 22:13, Bill Guion bgu...@comcast.net wrote:


  So if I understand, you want an explode() with empty parameters to
explode
  the host machine?


That's correct.  If it causes too much userland confusion, we can
 alias it as detonate() as well.


 Yes, to be preceded with:

 echo('Alaho Akbar');


Nice ... any idea how many people you just insulted there?


Re: [PHP] phpsadness

2011-06-03 Thread Peter Lind
On Jun 3, 2011 4:52 PM, Paul M Foster pa...@quillandmouse.com wrote:

 On Fri, Jun 03, 2011 at 04:23:54PM +0200, Peter Lind wrote:

  On Jun 3, 2011 3:48 PM, tedd tedd.sperl...@gmail.com wrote:
  
   At 1:02 PM -0400 6/2/11, Daniel Brown wrote:
  
   On Tue, May 31, 2011 at 22:13, Bill Guion bgu...@comcast.net wrote:
  
  
So if I understand, you want an explode() with empty parameters to
  explode
the host machine?
  
  
  That's correct.  If it causes too much userland confusion, we can
   alias it as detonate() as well.
  
  
   Yes, to be preceded with:
  
   echo('Alaho Akbar');
  
 
  Nice ... any idea how many people you just insulted there?

 I'm guessing no one with an actual sense of humor.

 I suspect most people snickered at the joke and admired the chutzpah it
 took to post it.


Admiring people that insult an entire religion? Really, it does not take
chutzpah, it just takes ignorance or stupidity to do something like that.
Nothing admirable about it.


Re: [PHP] phpsadness

2011-06-03 Thread Peter Lind
On 3 June 2011 17:36, Stuart Dallas stu...@3ft9.com wrote:
 On Fri, Jun 3, 2011 at 4:14 PM, Peter Lind peter.e.l...@gmail.com wrote:

 On Jun 3, 2011 4:52 PM, Paul M Foster pa...@quillandmouse.com wrote:
 
  On Fri, Jun 03, 2011 at 04:23:54PM +0200, Peter Lind wrote:
 
   On Jun 3, 2011 3:48 PM, tedd tedd.sperl...@gmail.com wrote:
   
At 1:02 PM -0400 6/2/11, Daniel Brown wrote:
   
On Tue, May 31, 2011 at 22:13, Bill Guion bgu...@comcast.net
wrote:
   
   
 So if I understand, you want an explode() with empty parameters
to
   explode
 the host machine?
   
   
   That's correct.  If it causes too much userland confusion, we
can
alias it as detonate() as well.
   
   
Yes, to be preceded with:
   
echo('Alaho Akbar');
   
  
   Nice ... any idea how many people you just insulted there?
 
  I'm guessing no one with an actual sense of humor.
 
  I suspect most people snickered at the joke and admired the chutzpah it
  took to post it.
 

 Admiring people that insult an entire religion? Really, it does not take
 chutzpah, it just takes ignorance or stupidity to do something like that.
 Nothing admirable about it.

 There's everything admirable about it. Religion is not special, and does not
 deserve any special treatment when it comes to critical comment. I can say
 anything I want about a particular political party and that's ok, but I
 can't express an opinion about a particular religion because it may cause
 offence?

Tedd's comment suggested that muslims are suicide bombers. That's not
a comment on religion, that's an insult to a large group of people.
Learn to tell the difference.

 And that's not to mention the fact that tedd's comment is a fact - more than
 a few people have detonated in the name of their religion, and chances are
 that if someone does detonate themselves it will be in the name of their
 religion.

And the vast majority of religious never have, nor never will detonate
in the name of religion. Yet they are being targeted and put to hate
just the same - then afterwards told to shut up and not feel offended.

 He didn't imply that everyone who follows that religion would do
 the same, but that's the only interpretation I can think of that would cause
 offence, so surely the offence is in the interpretation not the actual
 words.

Ahh, I see, that's why he wrote Praise Jesus and not Alaho Akbar -
he really didn't mean to say anything about muslims or islam as a
whole, he only wanted to comment on religion in an abstract way.

 Offence, like all things, is in the eye of the beholder. If something
 offends you, take responsibility for the fact that it's because someone is
 challenging a belief that you don't want to be challenged so you're reacting
 against it. It's not because it is objectively offensive. There is nothing
 that is objectively offensive*.

The fact that someone offends someone else is neither more nor less an
issue just because the offence is subjective. If I hold a certain
belief and you choose to stuff that down the toilet, you're a complete
dick, whether or not my belief makes sense.

And for the record, Tedd did not challenge any beliefs. He just made a
stupid joke at the expense of muslims.


 * Nothing is objectively anything. Everything is subjective.

Pure, unadulterated BS.

Peter

-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

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



Re: [PHP] phpsadness

2011-06-03 Thread Peter Lind
On 3 June 2011 20:42, tedd tedd.sperl...@gmail.com wrote:
 At 4:23 PM +0200 6/3/11, Peter Lind wrote:

 On Jun 3, 2011 3:48 PM, tedd
 mailto:tedd.sperl...@gmail.comtedd.sperl...@gmail.com wrote:
      That's correct.  If it causes too much userland confusion, we can
   alias it as detonate() as well.

   Yes, to be preceded with:

   echo('Alaho Akbar');
  

 Nice ... any idea how many people you just insulted there?

 Nope, and I don't think you do either.

 Instead, I think you saw an opportunity to be politically correct and rise
 to the occasion in righteous indignation.

I think you'll do anything to avoid facing the fact that you might
indeed have done some morally wrong. Or maybe I don't. It doesn't
matter - the question is whether or not you actually insulted a large
group of people by suggesting that detonate() should be prefixed with
echo Alaho akbar;

 That's Okay, but the problem with politically correctness is that it often
 suppresses the truth in favor of meaningless sensitivity.

We agree here, but unfortunately for you that's not the point being discussed.

 Unfortunately, the inconvenient truth is that phrase *IS* being spoken
 before killing innocent men, women, and children supposedly in the name of
 God. If anyone should be insulted, it should be those families who's that
 practice has killed, maimed, and injured -- as well -- as the followers of
 that religion who allow such practices to continue.

Do you feel better knowing you may have insulted even more people?
Does that thought even occur to you?

 My stupid little joke has no meaning in the overall scheme of things as does
 your righteous indignation -- so, with all due respect, blow it out your
 shorts. :-)

No, see, there's the problem. Your stupid little joke just makes it a
little bit harder to actually cross the gap between the different
cultures. And while that may be fine for you, I'd prefer actually
being able to speak to people from other cultures about the problems
we face. Having someone suggest that bombs go Alaho akbar before
they detonate don't help in any way, as that just promotes two
stereotypes: that suicide bombers are muslims, and that westerners are
stupid jerks that think all muslims are terrorists.

Anyway, I won't bother you with my political correctness any more -
the list has reached a too high noise-and-bs-to-signal ratio for me.

Peter

-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

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



Re: [PHP] phpsadness

2011-05-28 Thread Peter Lind
On May 28, 2011 11:27 AM, Andre Polykanine an...@oire.org wrote:

 Hello Lester,

 Actually,  many of the points are not important for me so far, however
 this one really drives me mad:
 http://phpsadness.com/?page=sad/35   (can't   explode()  by  an  empty
 string)

http://www.php.net/manual/en/function.str-split.php

Regards


Re: [PHP] Check the byte sequence of a file to tell if it is UTF-8 without the BOM using PHP ?

2011-05-22 Thread Peter Lind
On 22 May 2011 08:17, Eli Orr (Office) eli@logodial.com wrote:
 Hi Adam,

 I have a prof that the XML advise does not work in real cases I had.
 We are using XMLs in our system but when you edit the XML with  a text
 editor and put the XML heading of UTF-8
 ?xml version=1.0 encoding=UTF-8?

 it DOES NOT assure the text inside is encoded in UTF-8 so but maybe (many
 cases) t other iso-xxx method.

The point of the header is telling readers what encoding is used. Of
course that means errors are possible - setting the header is not
magic, it doesn't change the rest of the file. You need to make sure
the contents of the file match the encoding from the header when you
make XML documents.

Anyway, from your perspective, the header is an indication but not a
foolproof way of figuring encoding out.

 My question was for a function that scan the bytes of the file and decided
 WITHOUT the BOM heading.
 I mean by checking the bytes sequence in the file.

 I claim that WITHOUT a BOM it might be impossible to assure it is UTF-8
 encoding which is a whole escape sequence logic
 that may convert one character into one, two or three character.

http://se.php.net/manual/en/function.mb-detect-encoding.php - the
first comment should be interesting to you.

*
If you try to use mb_detect_encoding to detect whether a string is
valid UTF-8, use the strict mode, it is pretty worthless otherwise.

?php
$str = 'áéóú'; // ISO-8859-1
mb_detect_encoding($str, 'UTF-8'); // 'UTF-8'
mb_detect_encoding($str, 'UTF-8', true); // false
?


Regards
Peter

-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

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



Re: [PHP] Check the byte sequence of a file to tell if it is UTF-8 without the BOM using PHP ?

2011-05-22 Thread Peter Lind
On 22 May 2011 09:03, Eli Orr (Office) eli@logodial.com wrote:
 Dear Peter,

 But my point was different.

 If you DO NOT have any BOM of a File does

 mb_detect_encodin

 can detect the file type by scanning the whole file ??


A few points:
1. top-posting on this list is frowned upon. Please bottom-post.
2. I did not write anything about BOM as far as I can recall. Neither
does the page I linked to contain much about BOM (I really suggest
reading it - as pointed out, the first comment should help you)

Regards
Peter

-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

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



Re: [PHP] context when calling non static method of class in a static way

2011-05-22 Thread Peter Lind
class A {
public function b() {
echo get_class($this);
}
static function c() {
echo get_class($this);
}
}

class B {
public function test(){
A::b();
A::c();
}
}
$b = new B;
$b-test();

Generates:
Strict Standards: Non-static method A::b() should not be called
statically, assuming $this from incompatible context in /tmp/test.php
on line 14
B
Notice: Undefined variable: this in /tmp/test.php on line 8
A

I would never use code generating warnings and notices like that. I'd
look into late static bindings instead:
http://php.net/manual/en/language.oop5.late-static-bindings.php

Regards
Peter

-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

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



Re: [PHP] Script ID?

2011-05-21 Thread Peter Lind
On 21 May 2011 16:18, Stuart Dallas stu...@3ft9.com wrote:
 On Sat, May 21, 2011 at 3:11 PM, tedd t...@sperling.com wrote:

 Hi gang:

 Okay, so,what's the best (i.e., most secure) way for your script to
 identify itself *IF* you plan on using that information later, such as the
 value in an action attribute in a form?

 For example, I was using:

 $self = basename($_SERVER['SCRIPT_NAME']);

 form name=my_form action=?php echo($self); ? method=post 

 However, that was susceptible to XSS.

 http://www.mc2design.com/blog/php_self-safe-alternatives

 says a simple action=# would work.

 But is there a better way?

 What would do you do solve this?


 If you want the form to submit to the same URL that generated the form, I'd
 recommend using $_SERVER['REQUEST_URI']. You can also omit the action
 attribute entirely which, in my experience, will cause the browser to submit
 to the current URL. I have no idea whether that's part of the HTML spec, but
 that's the behaviour I've always observed.

REQUEST_URI is as susceptible to XSS as the others. Omitting url
entirely (in case of posting a form, say) works in most browsers but
is known to fail in others (atm I can't recall which but Google should
know). Both '?' and '#' will generally work, but are prone to problems
with the base element.

 Alternatively, by my reckoning, you could make your use of PHP_SELF safe by
 applying rawurlencode to $self when you put it in the action, but that's
 only after 30 seconds of thinking about it.

rawurlencode encodes forward slashes (and many other things). Not what
you're looking for.

Apart from that, there is no single solution to the issue: if you're
doing url rewrites, then you could use your route-to-url function
instead of relying on any server variables. If your script is called
directly instead, then use the part of the request uri up till and
including the match for __FILE__.

Regards
Peter

-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

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



Re: [PHP] Script ID?

2011-05-21 Thread Peter Lind
On 21 May 2011 17:01, Stuart Dallas stu...@3ft9.com wrote:
 On Sat, May 21, 2011 at 3:35 PM, Peter Lind peter.e.l...@gmail.com wrote:

 On 21 May 2011 16:18, Stuart Dallas stu...@3ft9.com wrote:
  On Sat, May 21, 2011 at 3:11 PM, tedd t...@sperling.com wrote:
 
  Hi gang:
 
  Okay, so,what's the best (i.e., most secure) way for your script to
  identify itself *IF* you plan on using that information later, such as
  the
  value in an action attribute in a form?
 
  For example, I was using:
 
  $self = basename($_SERVER['SCRIPT_NAME']);
 
  form name=my_form action=?php echo($self); ? method=post 
 
  However, that was susceptible to XSS.
 
  http://www.mc2design.com/blog/php_self-safe-alternatives
 
  says a simple action=# would work.
 
  But is there a better way?
 
  What would do you do solve this?
 
 
  If you want the form to submit to the same URL that generated the form,
  I'd
  recommend using $_SERVER['REQUEST_URI']. You can also omit the action
  attribute entirely which, in my experience, will cause the browser to
  submit
  to the current URL. I have no idea whether that's part of the HTML spec,
  but
  that's the behaviour I've always observed.

 REQUEST_URI is as susceptible to XSS as the others. Omitting url
 entirely (in case of posting a form, say) works in most browsers but
 is known to fail in others (atm I can't recall which but Google should
 know). Both '?' and '#' will generally work, but are prone to problems
 with the base element.

 Yup, should have said that anything you use should be escaped.

  Alternatively, by my reckoning, you could make your use of PHP_SELF safe
  by
  applying rawurlencode to $self when you put it in the action, but that's
  only after 30 seconds of thinking about it.

 rawurlencode encodes forward slashes (and many other things). Not what
 you're looking for.

 Note that I said your use, and tedd is running basename on the PHP_SELF
 variable before using it so the escaping of forward slashes is not an issue
 here hence why I didn't mention it.

 Apart from that, there is no single solution to the issue: if you're
 doing url rewrites, then you could use your route-to-url function
 instead of relying on any server variables. If your script is called
 directly instead, then use the part of the request uri up till and
 including the match for __FILE__.

 There is a single solution... know what URL you should be using at any given
 point without making it depend on user(/browser)-supplied data. If you don't
 know what URL you should be using at any given point, your architecture is
 fundamentally flawed, whether than means passing it into shared code from
 elsewhere, or using a single block of code to generate your URLs. In my
 opinion you should never be generating URLs based on the URL that was used
 to request the page.

That is not a single solution - that is a general approach, for which
the solution will look different based on whether or not you use url
rewriting, actual script filenames, etc. etc. The point wasn't that
there are no solutions, just that the solution to Tedd's problem
depends upon how he's doing PHP in general.

 If you must generate it using that source, rawurlencode is still the way to
 go. To get around the forward slash issue, replace all / with ~~~ (or
 similar text that won't be modified by rawurlencode), run rawurlencode then
 replace ~~~ with /. Wrap that up in a nice little function, and apply
 liberally.

Again, this depends upon what your url scheme looks like - and without
knowing that, there's simple no clue as to whether or not this is a
good solution to the problem (though it might be a good solution to A
problem).

Regards
Peter

-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

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



Re: [PHP] Script ID?

2011-05-21 Thread Peter Lind
On 21 May 2011 17:18, Stuart Dallas stu...@3ft9.com wrote:

*snip*

 Again, this depends upon what your url scheme looks like - and without
 knowing that, there's simple no clue as to whether or not this is a
 good solution to the problem (though it might be a good solution to A
 problem).

 Again, I disagree. If you have an example of a URL structure where this
 would not work I'd love to hear it.
 -Stuart

Having to replace several times just in order to figure out the path
to your script is pointless if you know the name of the script (which
you always do - it's __FILE__ ) and you're using a one-to-one
request-to-script scheme. Then just grab the part of the url up to and
including your scriptname.

Note I used the word good - doing several str_replace() and other
calls is not what I consider a good solution if there's something
simpler available with as good a result.

Regards
Peter

-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

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



Re: [PHP] Script ID?

2011-05-21 Thread Peter Lind
On 21 May 2011 17:34, Stuart Dallas stu...@3ft9.com wrote:
 On Sat, May 21, 2011 at 4:24 PM, Peter Lind peter.e.l...@gmail.com wrote:

 On 21 May 2011 17:18, Stuart Dallas stu...@3ft9.com wrote:

 *snip*

  Again, this depends upon what your url scheme looks like - and without
  knowing that, there's simple no clue as to whether or not this is a
  good solution to the problem (though it might be a good solution to A
  problem).
 
  Again, I disagree. If you have an example of a URL structure where this
  would not work I'd love to hear it.
  -Stuart

 Having to replace several times just in order to figure out the path
 to your script is pointless if you know the name of the script (which
 you always do - it's __FILE__ ) and you're using a one-to-one
 request-to-script scheme. Then just grab the part of the url up to and
 including your scriptname.

 Well, it would be basename(__FILE__), but that's beside the point. In this
 particular case, where the PHP filename is the last part of the URL, that
 will indeed work. However, as you have pointed out several times that's not
 always the case and I tend to write generic, defensive code rather than make
 assumptions.

Not a bad habit. I would personally go with let's either find out or
make a decision instead of wasting time on coding for situations that
will crop up.


 Note I used the word good - doing several str_replace() and other
 calls is not what I consider a good solution if there's something
 simpler available with as good a result.

 Obviously that's your choice to make, but these days I very rarely work on
 projects where there is a one-to-one mapping, and even if I did I would not
 rely on that always being the case. I've worked on a number of projects
 where the URL structure has been massively changed (a couple from one-to-one
 to controller-based) where it would have taking an excessive amount of time
 to undo that assumption.
 Using rawurlencode on $_SERVER['REQUEST_URI'] is flexible, largely
 future-proof and takes no more effort than the manipulation you are doing on
 __FILE__ to get the same result. Given the choice I'll always go for 10%
 extra work now to save 90% extra work later, even if it's only potential
 work later.

I can generally agree with that, depending on project though.

Regards
Peter

-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

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



Re: [PHP] Script ID?

2011-05-21 Thread Peter Lind
On 21 May 2011 18:05, Stuart Dallas stu...@3ft9.com wrote:
 On Sat, May 21, 2011 at 4:57 PM, Peter Lind peter.e.l...@gmail.com wrote:

 On 21 May 2011 17:34, Stuart Dallas stu...@3ft9.com wrote:
  On Sat, May 21, 2011 at 4:24 PM, Peter Lind peter.e.l...@gmail.com
  wrote:
 
  On 21 May 2011 17:18, Stuart Dallas stu...@3ft9.com wrote:
 
  *snip*
 
   Again, this depends upon what your url scheme looks like - and
   without
   knowing that, there's simple no clue as to whether or not this is a
   good solution to the problem (though it might be a good solution to
   A
   problem).
  
   Again, I disagree. If you have an example of a URL structure where
   this
   would not work I'd love to hear it.
   -Stuart
 
  Having to replace several times just in order to figure out the path
  to your script is pointless if you know the name of the script (which
  you always do - it's __FILE__ ) and you're using a one-to-one
  request-to-script scheme. Then just grab the part of the url up to and
  including your scriptname.
 
  Well, it would be basename(__FILE__), but that's beside the point. In
  this
  particular case, where the PHP filename is the last part of the URL,
  that
  will indeed work. However, as you have pointed out several times that's
  not
  always the case and I tend to write generic, defensive code rather than
  make
  assumptions.

 Not a bad habit. I would personally go with let's either find out or
 make a decision instead of wasting time on coding for situations that
 will crop up.

 Assumptions cost money, and if you haven't discovered that yet then you've
 either not been in the software development game very long or you've been
 lucky so far. Hold on to that feeling, cos you can't get it back when it's
 gone!

Assumptions and knowledge are two different things. If you haven't
discovered that yet then you've either not been in the software
development game very long or you've been doing things wrong so far. I
suggest spending some time checking up on the difference.

Regards
Peter

-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

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



Re: [PHP] Script ID?

2011-05-21 Thread Peter Lind
On 21 May 2011 18:26, Stuart Dallas stu...@3ft9.com wrote:

*snip*

 http://en.wikipedia.org/wiki/Defensive_programming
 You do things your way and I'll do things my way. Best of luck to you.

Thank you for your condescending tone. Best of luck to you too.

Regards
Peter

-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

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



Re: [PHP] Script ID?

2011-05-21 Thread Peter Lind
On 21 May 2011 18:42, Stuart Dallas stu...@3ft9.com wrote:
 On Sat, May 21, 2011 at 5:33 PM, Peter Lind peter.e.l...@gmail.com wrote:

 On 21 May 2011 18:26, Stuart Dallas stu...@3ft9.com wrote:

 *snip*

  http://en.wikipedia.org/wiki/Defensive_programming
  You do things your way and I'll do things my way. Best of luck to you.

 Thank you for your condescending tone. Best of luck to you too.

 It is regrettable if you took offence, but I stand by my tone. I've cleaned
 up too many messes over the years that were caused by careless (and in some
 cases incompetent) assumptions that I have little time for anyone who
 doesn't see the value in expecting the unexpected.

Yet you assume that I have no experience, have never cleaned up messes
after others, and generally have no clue what I'm talking about. At no
point did I state that I see no value in expecting the unexpected or
that I disagree with defensive programming. What I did state is that I
prefer clearing up any unclear areas and remove assumptions - if I end
up spending most of my time doing defensive programming because I
haven't cleared up the specifications with the client, then I have
done a very poor job.

Anyway, I doubt there's much point in continuing the conversation -
you seem to have a set worldview and it appears that my role in it is
the same regardless of what I state from here on out.

So: best of luck to you.

Regards
Peter

-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

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



Re: Re: [PHP] A Review Request

2011-05-20 Thread Peter Lind
On 20 May 2011 11:20, Tim Streater t...@clothears.org.uk wrote:

*snip*

 [...] is marked as being aimed at the novice, and at the same time lists some 
 of the areas that deliberately haven't been addressed in the example 
 provided, then that should suffice.


Apart from the above that would make great additions, would also be
great to see some links of where to get info on the subjects that are
not covered (such as security) so that people could find out more on
those topics.

Regards
Peter

-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

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



Re: [PHP] Re: Date validation

2011-05-20 Thread Peter Lind
On 20 May 2011 16:22, Geoff Lane ge...@gjctech.co.uk wrote:
  On Friday, May 20, 2011, João Cândido de Souza Neto wrote:

 What about using this:

 $date = DateTime::createFromFormat(Y-m-d, 2011-05-20);

 Hi João, and thanks for your help.

 FWIW, I thought about that but it didn't work for me. On further
 investigation, I'm now completely confused and suspect I've got a duff
 PHP installation. Thankfully, it's a virtual machine so it should be
 reasonable easy to 'vapourise' and start over (perhaps with CentOS
 rather than Ubuntu as the OS).

 Anyway, the following code produces the following result when the
 variable $str = '7 feb 2010':

 [code]
  echo pDate is $str/p\n;
  $date = DateTime::createFromFormat('d M Y', $str);
  echo pre;
  print_r($date);
  echo /pre\n;
  echo date('d M Y') . br / . date('d M Y', $date);
 [/code]

 [result]
  pDate is 7 feb 2010/p
  preDateTime Object
  (
      [date] = 2010-02-07 15:11:34
      [timezone_type] = 3
      [timezone] = Europe/London
  )
  /pre
  20 May 2011br /
 [/result]

 This is pretty much as expected except that the second call to date()
 - i.e. date('d M Y', $date) - outputs nothing.

date() takes an int as second parameter - a timestamp. Not an object.
And from a quick test it doesn't look like DateTime has a __toString
method.

 Also, AFAICT createFromFormat fails if the date is not formatted
 according to the first parameter. So, for example:
  $date = DateTime::createFromFormat('d M Y', '5/2/10')
 fails ... (at least, it does on my system :( )


I'm sorry for asking but what did you expect?? You're specifically
calling a method that parses a string according to a given format. If
it parsed the string according to any other format, that would be a
huge WTF.

Regards
Peter

-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

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



Re: [PHP] Re: Date validation

2011-05-20 Thread Peter Lind
2011/5/20 João Cândido de Souza Neto j...@consultorweb.cnt.br:
 If you look carefully, you´ll notice that I´m using the DateTime object
 (default from PHP 5.2.0 or higher) not the function date.

If you look carefully, you'll notice that I replied to Geoff.

Regards
Peter

-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

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



Re: [PHP] Re: Date validation

2011-05-20 Thread Peter Lind
On 20 May 2011 16:47, Geoff Lane ge...@gjctech.co.uk wrote:

*snip*

 Also, AFAICT createFromFormat fails if the date is not formatted
 according to the first parameter. So, for example:
  $date = DateTime::createFromFormat('d M Y', '5/2/10')
 fails ... (at least, it does on my system :( )


 I'm sorry for asking but what did you expect?? You're specifically
 calling a method that parses a string according to a given format. If
 it parsed the string according to any other format, that would be a
 huge WTF.

 Don't feel sorry to have asked, because it's exactly what I expected.
 João suggested using createFromFormat. Since I need to validate dates
 input in any valid form, I felt it wouldn't work and my comment was to
 João to that effect. That said, I've seen some weird and unexpected
 results from my development server recently (e.g. my post of 16 May re
 weird cookie behaviour) which was why I added the proviso (at least,
 it does on my system) just in case that method wasn't meant to behave
 as I inferred.

 With all that said, I still have no 'out of the box' method to
 validate a user-input date string and I haven't been able to find the
 code I used with PHP 3.something before my sojourn into the depths of
 ASP to know how I used to do this!


My bad, I jumped into the middle of a thread - sorry.

Try:

$date = new DateTime($date_string_to_validate);
echo $date-format('Y-m-d');

Regards
Peter

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



Re: [PHP] A Review Request

2011-05-18 Thread Peter Lind
On 18 May 2011 22:34, tedd t...@sperling.com wrote:
 At 3:31 PM -0400 5/18/11, Joshua Kehn wrote:

 On May 18, 2011, at 3:22 PM, tedd wrote:

 I am considering providing PHP code to the general public via my website

 This is my first attempt:


 http://sperling.com/php/authorization/http://sperling.com/php/authorization/

 What do you people think?


Good initiative. One thing though:
Please do not EVER suggest that people copy/paste your code. Do NOT
provide a nice option for copying it or suggest that it will work if
you just copy this and add a suffix. Plenty of people will mess
things up somehow, you'll discover a bug somewhere, etc. etc.
Copypasted code is one of the worst things the web has done. So please
don't add to it :)

Regards
Peter

-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

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



Re: [PHP] A Review Request

2011-05-18 Thread Peter Lind
On 18 May 2011 23:12, tedd t...@sperling.com wrote:
 At 10:55 PM +0200 5/18/11, Peter Lind wrote:

 On 18 May 2011 22:34, tedd t...@sperling.com wrote:

  At 3:31 PM -0400 5/18/11, Joshua Kehn wrote:

  On May 18, 2011, at 3:22 PM, tedd wrote:

  I am considering providing PHP code to the general public via my
 website

  This is my first attempt:

  
   http://sperling.com/php/authorization/
   What do you people think?

 Good initiative. One thing though:
 Please do not EVER suggest that people copy/paste your code. Do NOT
 provide a nice option for copying it or suggest that it will work if
 you just copy this and add a suffix. Plenty of people will mess
 things up somehow, you'll discover a bug somewhere, etc. etc.
 Copypasted code is one of the worst things the web has done. So please
 don't add to it :)

 Regards
 Peter

 Peter:

 Thanks, but the point here *is* to get people involved using PHP.

Good and noble intent. Does not in any way have anything to do with copypasting.

 The code I've placed in the Copy/Paste sections will work as-is *IF* the
 users follow directions. I've tested it and it does work.

*IF* the users follow directions - a lot of them won't. Some of them
will copypaste it into different environments than you have envisaged.
Then someone will probably also find a bug in it at some point.

 Granted, for over a dozen years I've provided various code to users and
 have more than my share of stories to tell of how they don't follow
 directions -- just take a look at my Web Tips pages. However, I would have
 greatly appreciated someone showing me what an include was back in 1998. It
 could have saved me a lot of trouble.

You make my point for me but for some reason don't want to follow the
logical conclusion of it. Why?

 This is just one way to give-back.

Suggesting people that they copypaste your code is a very bad way of
giving back. Suggesting that they read and understand the code is a
great way. I hope you see the difference.

Regards
Peter

-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

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



Re: Re: [PHP] A Review Request

2011-05-18 Thread Peter Lind
On 18 May 2011 23:28, Tim Streater t...@clothears.org.uk wrote:
 On 18 May 2011 at 22:22, Peter Lind peter.e.l...@gmail.com wrote:

 On 18 May 2011 23:12, tedd t...@sperling.com wrote:

 This is just one way to give-back.

 Suggesting people that they copypaste your code is a very bad way of
 giving back. Suggesting that they read and understand the code is a
 great way. I hope you see the difference.

 Not obvious. If I have copy/pasted code and it hasn't worked, that's been 
 no-one's fault but mine, and I've then gone back and looked at it more 
 carefully. Any example given on the web, seems to me, is likely to be 
 copy/pasted unless you take steps to make it not possible.


I personally don't care if someone comes back whining to Tedd after
copypasting the code. I would think it sad but it doesn't affect me as
such. What I do care about are the people that will mindlessly
copypaste the code, get it into halfworking state mixed with some
other strange stuff that they picked up from some other site, then
throw the whole together on a server and start telling their friends
how awesomely easy php is and that they should just copypaste *their*
code (not Tedd's because his only does a bit of the job).

As is probably clear by now, in my opinion it would be much better to
go the motions of the script a bit at a time, with comments of *why*
things are done (not *what* is done) - and why you really should spend
a bit more time learning about security, because if you copypaste
Tedd's script and just change the password to 'mypass', you won't have
learned a thing even as your script is bruteforced in 2 seconds flat.

Anyway, I doubt I have much more to add to this so I'll refrain from it.

Regards
Peter

-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

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



Re: [PHP] A Review Request

2011-05-18 Thread Peter Lind
On 18 May 2011 23:50, tedd t...@sperling.com wrote:
 At 11:22 PM +0200 5/18/11, Peter Lind wrote:

 On 18 May 2011 23:12, tedd t...@sperling.com wrote:

   Thanks, but the point here *is* to get people involved using PHP.

 Good and noble intent. Does not in any way have anything to do with
 copypasting.

 That's more of an argument than a fact -- and I don't feel comfortable
 calling it copypasting. I'll stick with calling the practice Copy/Paste as
 defined by Apple. Sure, people can argue that M$ invented the practice, as
 they did everything else, but I remember M$ claiming that the mouse wouldn't
 make it, and that was before Copy/Paste.  :-)

 Back to point, I just spent 16 week teaching 16 college students via
 Introduction in PHP by giving them code to copy/paste.

 As a result, I saw most take-off and learn more than I taught. Sure, there
 were some who just didn't get it, but I think they would not have
 gotten-it even if I had forced them to hard-code everything. Some people
 are not geared for programming.

 ---


 *IF* the users follow directions - a lot of them won't. Some of them
 will copypaste it into different environments than you have envisaged.
 Then someone will probably also find a bug in it at some point.

 If they do find a bug, then I'll deal with it. But putting this link up for
 review by peers, as I've done here, is one way to help catch those bugs.

 --

   Granted, for over a dozen years I've provided various code to users
 and

  have more than my share of stories to tell of how they don't follow
  directions -- just take a look at my Web Tips pages. However, I would
 have
  greatly appreciated someone showing me what an include was back in 1998.
 It
  could have saved me a lot of trouble.

 You make my point for me but for some reason don't want to follow the
 logical conclusion of it. Why?

 I stated my reason, Perhaps I'm wrong, but that remains to be seen. However,
 it is not fact that your position is a logical conclusion -- it's just your
 conclusion.


Premise: The code I've placed in the Copy/Paste sections will work
as-is *IF* the users follow directions. I've tested it and it does
work.
Premise: Granted, for over a dozen years I've provided various code
to users and have more than my share of stories to tell of how they
don't follow directions -- just take a look at my Web Tips pages.

Logical conclusion: you cannot guarantee what you're trying to, namely
it does work.

Regards
Peter

-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

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



Re: [PHP] An Invitation to Neuroscientists and Physicists: Singapore Citizen Mr. Teo En Ming (Zhang Enming) Reports First Hand Account of Mind Intrusion and Mind Reading

2011-05-17 Thread Peter Lind
On May 17, 2011 5:05 PM, tedd tedd.sperl...@gmail.com wrote:

 At 1:19 PM +0100 5/17/11, Richard Quadling wrote:

 On 17 May 2011 12:45, Singapore Citizen Mr. Teo En Ming (Zhang Enming)
 -snip-

   Please remember what Singapore Citizen Mr. Teo En Ming (Zhang Enming)
have

  said. Mark my words. You will know the truth in future. It is no longer
a
  conspiracy theory. I can affirm that it (mind intrusion and mind
reading) is

   indeed happening to me.

 Is it Friday?

 Richard Quadling



 Wow! You read my mind.

 Cheers,

 tedd

If only it was ... then I'd be off work tomorrow, and the op and all the
replies would have been welcome noise instead of just noise. *sigh*

 --
 ---
 http://sperling.com/

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



Re: [PHP] Consistent Class Renaming (Simple Refactoring)

2011-05-17 Thread Peter Lind
On May 17, 2011 4:32 PM, Daniel Brown danbr...@php.net wrote:

 On Mon, May 16, 2011 at 18:46, Richard Quadling rquadl...@gmail.com
wrote:
 
  2.7.2? I'm guessing 5.7.2.

Then you're guessing wrong, sir.  There was no 2.7.2, and it's
 highly unlikely there would ever be a 5.7.2 either.

Closest I can guess is Apache httpd 2.2.7, or perhaps some other
 all-in-one installer (for example, there is a XAMPP 1.7.2).

Php 5.2.7 seems a more likely culprit

 --
 /Daniel P. Brown
 Network Infrastructure Manager
 http://www.php.net/

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



Re: Re: [PHP] Error recovery - fatal errors

2011-05-16 Thread Peter Lind
On 16 May 2011 22:14, Tim Streater t...@clothears.org.uk wrote:
 On 14 May 2011 at 15:05, Peter Lind peter.e.l...@gmail.com wrote:

 On 14 May 2011 12:33, Tim Streater t...@clothears.org.uk wrote:
 I would like, in my app, to recover from as many run-time errors as 
 possible,
 so that I can tidy up. And unsolicited output generated by the standard 
 error
 system is really unhelpful as it becomes part of the ajax reply to the
 browser.

 So I've added my own error handler, but it seems that I can't catch fatal
 errors. The error in question comes from doing something like:

 Fatal errors are fatal - if you could recover from them, they wouldn't be
 fatal.

 Except that this error is arbitrarily designated as fatal when it need not 
 be. A few days ago I discovered register_shutdown_function as mentioned by 
 someone today, and use that to pass E_ERRORs on to my error handler (as 
 declared by set_error_handler). That way I can log the error properly and 
 notify the user in a consistent manner. I've tested this by introducing some 
 errors (e.g. unitialised variables or setting $dbh to null) and these are all 
 nicely picked up.

You were trying to call a method on a non-object - how do you expect
PHP to handle that if not with a fatal error?
Anyway, good to hear you solved the issue - I misunderstood what you
wanted to do (shut down in a proper fashion, not actually recover from
the error) so I didn't think to mention this.

* snip *

 You can avoid all problems with error output by turning off error
 displays in php.ini (set display_errors = off) - use error logging
 instead. That's the recommended setting for production servers.

 This is not a browser/webserver situation in the classic manner. In this 
 case, the browser, PHP code, and the instance of apache used are all running 
 on the user's machine. The user just thinks they are running a local 
 application.

You can call it production server or not, if you are having problems
with error messages from php then you should turn off error display -
which shouldn't get in the way of you showing your own error messages
but will solve the problem mentioned.

Regards
Peter

-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

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



Re: [PHP] Error recovery - fatal errors

2011-05-14 Thread Peter Lind
On 14 May 2011 12:33, Tim Streater t...@clothears.org.uk wrote:
 I would like, in my app, to recover from as many run-time errors as possible, 
 so that I can tidy up. And unsolicited output generated by the standard error 
 system is really unhelpful as it becomes part of the ajax reply to the 
 browser.

 So I've added my own error handler, but it seems that I can't catch fatal 
 errors. The error in question comes from doing something like:

Fatal errors are fatal - if you could recover from them, they wouldn't be fatal.

 $res = $dbh-query ($sql);

 with $sql being an SQL statement, and $dbh being a database handle. I 
 recently had a case where $dbh was NULL, which triggers a fatal error from 
 SQLite. In principle such a bug should show up quickly, but this one had lain 
 untriggered for about a year. It seems to me somewhat arbitrary for this to 
 be designated a fatal error. Is there a way I can catch these? Most SQLite 
 error situations I'm solving with try/catch but no luck with this one so far.

You've got something wrong: either $dbh is not null or the error is
not from sqlite. I'm guessing the former. To avoid situations like
that, do proper error checking (i.e. actually check that your database
connection was opened succesfully).

 Error handling in library packages seems somewhat arbitrary - e.g. opendir 
 may give an E_WARNING, but closedir, readdir don't.


You can avoid all problems with error output by turning off error
displays in php.ini (set display_errors = off) - use error logging
instead. That's the recommended setting for production servers.

Regards
Peter

-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

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



Re: [PHP] Odd array_push issue

2011-05-11 Thread Peter Lind
On 11 May 2011 22:23, Richard S. Crawford rich...@underpope.com wrote:
 I'm encountering what appears to be a bug in array_push when I try using
 that function to add objects to an array. For example...

 A = Object 1
 B = Object 2

 If I execute the following code:

 array_push(objectarray, A);
 array_push(objectarray, B);

 ...I expect the contents of $objectarray to be:

 [0] = A
 [1] = B

 Instead, the last object pushed onto the array is repeated throughout the
 array. In other words, instead of the above, I get this:

 [0] = B
 [1] = B

 Can anyone enlighten me as to why this is happening? I've looked through bug
 reports but haven't found anything, which leads me to think that perhaps my
 own code is at fault.


If you could post some more of your code, it would be easier to check
if your code is at fault or not.

Regards
Peter

-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

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



Re: [PHP] Odd array_push issue

2011-05-11 Thread Peter Lind
On 11 May 2011 22:39, Richard S. Crawford rich...@underpope.com wrote:
 On Wed, May 11, 2011 at 1:30 PM, Peter Lind peter.e.l...@gmail.com wrote:

 On 11 May 2011 22:23, Richard S. Crawford rich...@underpope.com wrote:
  I'm encountering what appears to be a bug in array_push when I try using
  that function to add objects to an array. For example...
 
  A = Object 1
  B = Object 2
 
  If I execute the following code:
 
  array_push(objectarray, A);
  array_push(objectarray, B);
 
  ...I expect the contents of $objectarray to be:
 
  [0] = A
  [1] = B
 
  Instead, the last object pushed onto the array is repeated throughout
  the
  array. In other words, instead of the above, I get this:
 
  [0] = B
  [1] = B
 
  Can anyone enlighten me as to why this is happening? I've looked through
  bug
  reports but haven't found anything, which leads me to think that perhaps
  my
  own code is at fault.
 

 If you could post some more of your code, it would be easier to check
 if your code is at fault or not.

 Regards
 Peter

 Here's some more sample code, then:

 
 function retrieve_records ($where) {
      (Returns an array of objects which represent rows from a database
 query)
 }

 $records = retrieve_records($condition);

 $recordlist  = array();

 foreach ($records as $record) {

  array_push ($recordlist, $record)

 }
 

 I know this code isn't very useful, but these are the conditions which cause
 the issue I've mentioned.

class a {
public function __construct() {
$this-rand = mt_rand();
}
}

function retrieve_records () {
return array(
new a,
new a,
new a,
new a,
new a,
);
}

$records = retrieve_records();

$recordlist  = array();

foreach ($records as $record) {
 array_push ($recordlist, $record);
}

die(var_dump($recordlist));

gives me:

array(5) {
  [0]=
  object(a)#1 (1) {
[rand]=
int(515141845)
  }
  [1]=
  object(a)#2 (1) {
[rand]=
int(804365869)
  }
  [2]=
  object(a)#3 (1) {
[rand]=
int(32698894)
  }
  [3]=
  object(a)#4 (1) {
[rand]=
int(1375725959)
  }
  [4]=
  object(a)#5 (1) {
[rand]=
int(100662005)
  }
}


I'd say there's a problem in your code. Check where you might be using
references, chances are you're using one somewhere and not unsetting
it afterwards.

Regards
Peter
-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

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



Re: [PHP] How to DUMP $_POST parameters to a log file? Very useful and missing in the php.net

2011-05-08 Thread Peter Lind
On May 8, 2011 1:57 PM, Eli Orr (Office) eli@logodial.com wrote:


 Dear PHP Gurus,

 I need dump a $_POST parameters as part of debug process with a client.
 Any know service to make this ?

 I know $_POST is an Array but I look for a service function  that can save
the parsed array into a file.
 let say :

 $stt = save_POST_into_file ($_POST, $fp);


file_put_contents($filename, print_r($array, true));

Regards


Re: [PHP] Wiki formatting class or something similar

2011-04-30 Thread Peter Lind
On 30 April 2011 15:13, Stuart Dallas stu...@3ft9.com wrote:
 On Friday, 29 April 2011 at 22:04, Andre Polykanine wrote:
 Hi everyone,
 I allow my users to put some Html into their blogs. I filter it using
 a great tool called HtmLawed and written by Dr. Santosh Patnaik (if
 you're reading this, many thanks to you!).
 However, I would like to give them a possibility to mark-up their text
 in a more convenient way for beginners (such as Wiki or something
 similar).
 I searched through http://phpclasses.org/ but didn't find anything.
 Could you suggest me something?
 And one more question: maybe some of you already have a handy solution
 to process smilies? Say, a user writes :) and this is replaced by an
 image in my directory.
 Thanks in advance!

 Markdown is a pretty good option for a wiki: 
 http://michelf.com/projects/php-markdown/

 Textile is another option (and supports tables which markdown does not): 
 http://textile.thresholdstate.com/


MarkItUp is a favourite plugin editor of mine - will allow you to work
with a lot of different syntaxes and users don't need to know them.

http://markitup.jaysalvat.com/home/

If you're considering sanitizing html instead of using a markup
language to convert into html, I'd read
http://blog.astrumfutura.com/2010/08/html-sanitisation-the-devils-in-the-details-and-the-vulnerabilities/
before settling on any tool to do the job. Far as I can tell, HtmLawed
isn't actually capable of sanitizing properly, according to the author
- unless it's since been updated to fix the problems mentioned in the
blog.

Regards
Peter

-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

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



Re: [PHP] Wiki formatting class or something similar

2011-04-30 Thread Peter Lind
On 30 April 2011 21:26, Andre Polykanine an...@oire.org wrote:
 Hello Peter,

 And what would you recommend as an Html sanitizing tool?


I go by htmlpurifier when I need to sanitize html. I generally try to
avoid the issue though, by having users use other markup languages (I
like markdown but dislike textile). That's much faster and just as
secure - downside is that your users might not be as used to it.

Regards
Peter

-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

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



Re: [PHP] XML... Useful or another layer of complexity?

2011-04-03 Thread Peter Lind
Like every other technology, XML needs to have a use before it becomes
a useful tool. Just using XML because it's available quickly leads to
headaches, as it isn't the best tool for all scenarios (config files
written in XML for instance). That said, XML is awesome for a lot of
things ... however, without having a better grasp of XML you're
unlikely to know whether it'll fit your needs.

If for no other reason, learning XML and related technologies is worth
it simply because the rest of the world uses it. So get to know it,
then you'll be able to actually judge if your project can benefit from
it.

Regards
Peter

-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

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



[PHP] Re: Config files: what is best? (was: Re: [PHP] XML... Useful or another layer of complexity?)

2011-04-03 Thread Peter Lind
On 3 April 2011 21:41, Andre Polykanine an...@oire.org wrote:
 Hello Peter,

 Just because you mentioned config files.
 What  would  you suggest me as better format for them? Database is not
 available  yet  since  I  need to make a config file before creating a
 database.

For config files I would suggest plain text config files - in the style of

key = value

php has built-in functions for reading those, so parsing them is very
fast and easy. See
http://dk2.php.net/manual/en/function.parse-ini-file.php

Regards
Peter

-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

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



Re: [PHP] Re: Config files: what is best? (was: Re: [PHP] XML... Useful or another layer of complexity?)

2011-04-03 Thread Peter Lind
On 3 April 2011 22:35, Andre Polykanine an...@oire.org wrote:
 Hello Peter,

 Thanks a lot! And is there a way to set (write) custom values in files
 other than php.ini? Sorry, didn't find such a function.


I haven't come across any, but then again, I haven't had the need so
never looked much ... It would be rather easy to generate though

Regards
Peter

-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

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



Re: [PHP] is there a static constructor?

2011-03-30 Thread Peter Lind
On 31 March 2011 06:56, D. Dante Lorenso da...@lorenso.com wrote:
 All,

 I want to build a config file class that gets called statically.  Is there
 such a thing as a static constructor?  Example:

 class Daz_Config {
  public static function load() {
    ...
  }
  public static function get($key) {
    self :: load();
    ...
  }
 }

 Daz_Config :: get('myvalue');

 I want to call the load function when the class is used for the first time.
  If no code ever calls Daz_Config :: get(...) then I never want to invoke
 load() but if it does get called, I only want to call load() once before the
 class is used further.

 Anyone know how to do this with calling load() at the top of all the other
 functions and writing a load() function that exits early if already loaded?


The concept doesn't really make sense - a class that never gets
instantiated never gets constructed, hence no static constructor (nor
a static destructor). You'll have to call your constructor function
at the top of the static methods you'll be using - just check inside
the constructor if it's been called before or not.

Regards
Peter


-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

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



Re: [PHP] session variable problem

2011-03-25 Thread Peter Lind
More info (including some code) would be needed to get to the bottom
of this, I'd say. Hard to diagnose what's happening otherwise.

Regards
Peter

-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

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



Re: [PHP] Deleting elements from the middle of an array

2011-03-15 Thread Peter Lind
On Mar 15, 2011 4:10 AM, Paul M Foster pa...@quillandmouse.com wrote:

 On Mon, Mar 14, 2011 at 10:14:53PM +0100, Peter Lind wrote:

  On 14 March 2011 22:10, Paul M Foster pa...@quillandmouse.com wrote:

 [snip]

   Remove the elements, then use sort().
  
   I've given a simplified example. The actual target array is
   multi-dimensional. Sort() won't work in a case like that, as far as I
   know. Moreover, I don't want the array sorted based on the element
   values.
 
  Ahh, I see - you wanted me to guess at the actual circumstances of the
  case instead of provide an answer to the example you posted. My bad.

 Is the sarcasm really necessary?


Without it, would you learn to post the actual details instead of something
irrelevant? If yes, then my apologies.

Regards


Re: [PHP] Deleting elements from the middle of an array

2011-03-15 Thread Peter Lind
On Mar 15, 2011 5:05 PM, Paul M Foster pa...@quillandmouse.com wrote:

 On Tue, Mar 15, 2011 at 07:08:28AM +0100, Peter Lind wrote:

 On Mar 15, 2011 4:10 AM, Paul M Foster [1]pa...@quillandmouse.com
 wrote:
 
  On Mon, Mar 14, 2011 at 10:14:53PM +0100, Peter Lind wrote:
 
   On 14 March 2011 22:10, Paul M Foster [2]pa...@quillandmouse.com

 wrote:
 
  [snip]
 
Remove the elements, then use sort().
   
I've given a simplified example. The actual target array is
multi-dimensional. Sort() won't work in a case like that, as
far as
 I
know. Moreover, I don't want the array sorted based on the
element
values.
  
   Ahh, I see - you wanted me to guess at the actual circumstances
of the
   case instead of provide an answer to the example you posted. My
bad.
 
  Is the sarcasm really necessary?
 
 
 Without it, would you learn to post the actual details instead of
 something irrelevant? If yes, then my apologies.

 Your sarcasm taught me more about you than about how to properly post to
 a mailing list.

 Help wrapped in a barbed package I can do without. Please feel free to
 ignore any requests for help from me in the future. Likewise, I will
 return the favor by ignoring any help you may give.


Duly noted - I shall regard any subsequent emails from you as having the
same degree of relevance as the information in your first email.


Re: [PHP] Deleting elements from the middle of an array

2011-03-14 Thread Peter Lind
On 14 March 2011 21:31, Paul M Foster pa...@quillandmouse.com wrote:
 Here's what I need to do: I have an indexed array, from which I need to
 delete elements in the middle. Once completed, the indexes should be
 numerically in sequence, as they were when I first encountered the
 array. That is:

 Before:
 $arr = array(0 = 5, 1 = 6, 2 = 7, 3 = 8, 4 = 9, 5 = 10);

 After:
 $arr = array(0 = 5, 1 = 6, 2 = 9, 3 = 10);


 I've tried:

 1) Using for() with unset(). Elements are deleted, but the indexes are
 no longer sequential.

 2) Using for() with array_splice(). Understandably, deletes certain
 elements but not others.

 3) Using foreach() with referenced array elements. Neither unset() nor
 array_splice() appear to have any effect on the array at all.

 4) while() loop using current() and the like. But these array functions
 return values, not references, so the array isn't actually modified.

 5) array_walk() with unset() array_splice(). No effect on the array.

 Anyone know how to do this, or know of a reference on how to?


Remove the elements, then use sort().

Regards
Peter


-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

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



Re: [PHP] Deleting elements from the middle of an array

2011-03-14 Thread Peter Lind
On 14 March 2011 22:10, Paul M Foster pa...@quillandmouse.com wrote:
 On Mon, Mar 14, 2011 at 09:34:33PM +0100, Peter Lind wrote:

 On 14 March 2011 21:31, Paul M Foster pa...@quillandmouse.com wrote:
  Here's what I need to do: I have an indexed array, from which I need to
  delete elements in the middle. Once completed, the indexes should be
  numerically in sequence, as they were when I first encountered the
  array. That is:
 
  Before:
  $arr = array(0 = 5, 1 = 6, 2 = 7, 3 = 8, 4 = 9, 5 = 10);
 
  After:
  $arr = array(0 = 5, 1 = 6, 2 = 9, 3 = 10);
 
 
  I've tried:
 
  1) Using for() with unset(). Elements are deleted, but the indexes are
  no longer sequential.
 
  2) Using for() with array_splice(). Understandably, deletes certain
  elements but not others.
 
  3) Using foreach() with referenced array elements. Neither unset() nor
  array_splice() appear to have any effect on the array at all.
 
  4) while() loop using current() and the like. But these array functions
  return values, not references, so the array isn't actually modified.
 
  5) array_walk() with unset() array_splice(). No effect on the array.
 
  Anyone know how to do this, or know of a reference on how to?
 

 Remove the elements, then use sort().

 I've given a simplified example. The actual target array is
 multi-dimensional. Sort() won't work in a case like that, as far as I
 know. Moreover, I don't want the array sorted based on the element
 values.

Ahh, I see - you wanted me to guess at the actual circumstances of the
case instead of provide an answer to the example you posted. My bad.


-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

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



Re: RE: [PHP] Check for open file

2011-03-03 Thread Peter Lind
On Mar 4, 2011 4:53 AM, Ashley M. Kirchner ash...@pcraft.com wrote:

  -Original Message-
  From: Ashley Sheridan [mailto:a...@ashleysheridan.co.uk]
  Sent: Thursday, March 03, 2011 2:03 PM
  To: sstap...@mnsi.net
  Cc: php-general@lists.php.net
  Subject: RE: [PHP] Check for open file
 
 
  As far as I was aware, if you're in the middle of writing to a file and
another
  script was attempting to write to it, the OS would prevent that as you
had an
  open lock on it.
 
  --
  Thanks,
  Ash
  http://www.ashleysheridan.co.uk
 

And as it turned out, that was not the case.  I started copying a
200MiB file from my desktop machine onto the Samba share.  While that was
copying, I got onto the server and tried to copy the file to /tmp and it
happily did that for me without any indication that it was still being
written to (which is was by the way.)  So, that's not a good way of dealing
with this.

I think I'm going to have to go with a time delay function here ...


If on Linux, you can check for open file with lsof, I think the command is
called.

Regards
Peter

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



[PHP] Infosys FYI

2011-02-26 Thread Peter Lind
Det gik op for mig at i tilmeldingsstresset fik jeg taget 2010
databasen ned. Den er nu tilgængelig igen.

Man bruger:
- http://archive.fastaval.dk/2010/infosys/ for at set 2010 udgaven
- http://infosys.fastaval.dk/ for at se 2011 udgaven

Derudover er 2009 udgaven stadig tilgængelig på
http://archive.fastaval.dk/2009/infosys/

De samme adgangskoder skulle virke til både 2010 og 2011.

Regards
Peter

-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

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



Re: [PHP] Regex pattern for preg_match_all

2011-02-18 Thread Peter Lind
On 18 February 2011 22:36, Tommy Pham tommy...@gmail.com wrote:
 Hi folks,

 This is not directly relating to PHP but it's Friday so I'm gonna give
 it a shot :).  Would someone please help me figure out why my regex
 pattern doesn't work.  Below is the code and sample data:

 $html = HTML
 li class=small  tab a class=y-mast-link images
 href=http://images.search.yahoo.com/images;
 data-b=http://www.yahoo.com;span class=tab-cover y-mast-bg-hide
 style=padding-left:0em;padding-right:0em;Images/span/a/li
 li class=small  tab a class=y-mast-link video
 href=http://video.search.yahoo.com/video;
 data-b=http://www.yahoo.com;span class=tab-cover y-mast-bg-hide
 style=padding-left:0em;padding-right:0em;Video/span/a/li
 li class=small  tab a class=y-mast-link local
 href=http://local.yahoo.com/results;
 data-b=http://www.yahoo.com;span class=tab-cover y-mast-bg-hide
 style=padding-left:0em;padding-right:0em;Local/span/a/li
 li class=small  tab a class=y-mast-link shopping
 href=http://shopping.yahoo.com/search;
 data-b=http://www.yahoo.com;span class=tab-cover y-mast-bg-hide
 style=padding-left:0em;padding-right:0em;Shopping/span/a/li
 li class=small lasttab more-tab a class=y-mast-link more
 href=http://tools.search.yahoo.com/about/forsearchers.html; span
 class=tab-cover y-mast-bg-hideMore/spanspan
 class=y-fp-pg-controls arrow/span/a/li
 HTML;

 $pattern = 
 '%a\s[^href]*href\s*=\s*[\'|]?([^\'||#]+)[\'|]?\s*[^]*(.*)?/a%im';
 preg_match_all($pattern, $html, $matches);

 The only matches I got is:

 Match 1 of 1:   a class=y-mast-link local
 href=http://local.yahoo.com/results;
 data-b=http://www.yahoo.com;span class=tab-cover y-mast-bg-hide
 style=padding-left:0em;padding-right:0em;Local/span/a

 Group 1:        http://local.yahoo.com/results

 Group 2:        span class=tab-cover y-mast-bg-hide
 style=padding-left:0em;padding-right:0em;Local/span

 The pattern I made was to work in cases where the page is
 non-compliant to any of standard W3.


Not entirely sure what your input data is, as I'm guessing one or more
mail programs may have added line breaks. When I run the code I get no
matches at all - so I'm guessing you might have different input on
your end. More specifically, I'm also guessing you have line breaks on
your end, but not equally distributed - which would explain the one
hit.
 Apart from that, there are a couple of things I'd rework in your regex:

%a\s+.*?(?!href)\s+href\s*=\s*([^\s\']+|\'[^\']+\'|\[^\]+\)[^]*(.*?)/a%ims

* added modifier to whitespace at first
* allowing for any character not followed by href (non-greedy)
* match the href
* use proper alternation
* capture anything inside the a tag, non-greedy
* match with a closing /a tag

Results:
array(3) {
  [0]=
  array(5) {
[0]=
string(205) a class=y-mast-link images
href=http://images.search.yahoo.com/images;
data-b=http://www.yahoo.com;span class=tab-cover y-mast-bg-hide
style=padding-left:0em;padding-right:0em;Images/span/a
[1]=
string(201) a class=y-mast-link video
href=http://video.search.yahoo.com/video;
data-b=http://www.yahoo.com;span class=tab-cover y-mast-bg-hide
style=padding-left:0em;padding-right:0em;Video/span/a
[2]=
string(196) a class=y-mast-link local
href=http://local.yahoo.com/results;
data-b=http://www.yahoo.com;span class=tab-cover y-mast-bg-hide
style=padding-left:0em;padding-right:0em;Local/span/a
[3]=
string(204) a class=y-mast-link shopping
href=http://shopping.yahoo.com/search;
data-b=http://www.yahoo.com;span class=tab-cover y-mast-bg-hide
style=padding-left:0em;padding-right:0em;Shopping/span/a
[4]=
string(188) a class=y-mast-link more
href=http://tools.search.yahoo.com/about/forsearchers.html; span
class=tab-cover y-mast-bg-hideMore/spanspan
class=y-fp-pg-controls arrow/span/a
  }
  [1]=
  array(5) {
[0]=
string(39) http://images.search.yahoo.com/images;
[1]=
string(37) http://video.search.yahoo.com/video;
[2]=
string(32) http://local.yahoo.com/results;
[3]=
string(34) http://shopping.yahoo.com/search;
[4]=
string(55) http://tools.search.yahoo.com/about/forsearchers.html;
  }
  [2]=
  array(5) {
[0]=
string(96) span class=tab-cover y-mast-bg-hide
style=padding-left:0em;padding-right:0em;Images/span
[1]=
string(95) span class=tab-cover y-mast-bg-hide
style=padding-left:0em;padding-right:0em;Video/span
[2]=
string(95) span class=tab-cover y-mast-bg-hide
style=padding-left:0em;padding-right:0em;Local/span
[3]=
string(98) span class=tab-cover y-mast-bg-hide
style=padding-left:0em;padding-right:0em;Shopping/span
[4]=
string(94) span
class=tab-cover y-mast-bg-hideMore/spanspan
class=y-fp-pg-controls arrow/span
  }


-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

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



Re: [PHP] Custom function

2011-02-16 Thread Peter Lind
On 16 February 2011 21:00, Dan Schaefer d...@performanceadmin.com wrote:
 In my code, I set the optional parameter to NULL and check for triple equals
 === or !== to see if the variable has been passed with a value. IMO,
 this is the safest way.

 function MyFunction($x, $y, $z=NULL) {
 if ($z !== NULL) {
 // Do Something
 }
 }

In case you're actually trying to test if a variable was passed or not
that doesn't work (as it doesn't detect NULL passed in). Use
func_get_args() as that gives you any and all arguments passed to the
function, excluding defaults.

That said, if you're making use of optional parameters and need to
check if anything was passed in, you're almost certainly doing things
wrong.

Regards
Peter

-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

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



Re: [PHP] Custom function

2011-02-16 Thread Peter Lind
On 16 February 2011 21:45, Andre Polykanine an...@oire.org wrote:
 Hello Peter,

 So is
 func_get_args()
     the unique way?


Not really sure what you mean by the unique way. Most things proposed
so far in the thread would be fine for most purposes, I'd say. If you
really need finegrained control, I'd suggest func_get_args.

Regards
Peter

-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

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



Re: [PHP] Custom function

2011-02-16 Thread Peter Lind
On 16 February 2011 21:45, Adam Richardson simples...@gmail.com wrote:
 On Wed, Feb 16, 2011 at 3:21 PM, Peter Lind peter.e.l...@gmail.com wrote:

 On 16 February 2011 21:00, Dan Schaefer d...@performanceadmin.com wrote:
  In my code, I set the optional parameter to NULL and check for triple
 equals
  === or !== to see if the variable has been passed with a value. IMO,
  this is the safest way.
 
  function MyFunction($x, $y, $z=NULL) {
  if ($z !== NULL) {
  // Do Something
  }
  }

 In case you're actually trying to test if a variable was passed or not
 that doesn't work (as it doesn't detect NULL passed in). Use
 func_get_args() as that gives you any and all arguments passed to the
 function, excluding defaults.


 I'm not sure what you're saying here, Peter? Are you saying that the code
 wouldn't detect if $z was set to NULL by the calling code or by the default?
 I believe the point would be that no matter the case, the check would still
 perform the same task.

 Maybe I misunderstood (sorry.)

The point is the poster seemed to suggest the safest way to use
optional parameters was to use null as the default value and use ===
null to check against the optional parameter - as a way to check if
anything was passed in or not. I just pointed out that that would fail
to check for a null passed in and that func_get_args() would be a
better match. You're obviously right that the check inside the
function would work the same whether null was passed in or the value
was defaulted to null.



 That said, if you're making use of optional parameters and need to
 check if anything was passed in, you're almost certainly doing things
 wrong.


 I sometimes use this approach. PHP doesn't to my knowledge allow you to use
 function calls within defaults. There are times that I want the default to
 be the result of a function, and to accomplish this, I'll often set the
 default to null, then check for the null and carry out the function within.

 Is there a better solution?

As noted in the post, func_get_args will show any and all (at least on
my 5.3.3 install and 5.2.6 install) values passed in to the function -
hence it will also show if no parameter was passed in (and is thus
safer than relying on the default value).
That noted, I don't think checking if a value was passed in is good
design - I think the function should be ignorant of what is passed to
it. But that's just me :)

Regards
Peter


-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

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



Re: [PHP] Custom function

2011-02-16 Thread Peter Lind
On 16 February 2011 22:04, Paul M Foster pa...@quillandmouse.com wrote:
 On Wed, Feb 16, 2011 at 09:21:20PM +0100, Peter Lind wrote:

 On 16 February 2011 21:00, Dan Schaefer d...@performanceadmin.com wrote:
  In my code, I set the optional parameter to NULL and check for triple
 equals
  === or !== to see if the variable has been passed with a value. IMO,
  this is the safest way.
 
  function MyFunction($x, $y, $z=NULL) {
  if ($z !== NULL) {
  // Do Something
  }
  }

 In case you're actually trying to test if a variable was passed or not
 that doesn't work (as it doesn't detect NULL passed in). Use
 func_get_args() as that gives you any and all arguments passed to the
 function, excluding defaults.

 This must be my week to make enemies.

 I beg to differ. If the user passes in NULL for $z or passes in nothing
 for that variable, it does in fact show up as NULL. The following test
 code works as indicated:

Did anyone say it wouldn't?


 The responses in the first and third cases are NULL. You might be able
 to argue that in the first case, where the user passed in NULL, it's
 not the same as if the user passed in nothing. But I would assume that the
 author considers NULL a signal value, such that if the user passed such
 a value in, it would be equivalent to not passing a value for the third
 parameter.

The point I was trying to make was specifically that someone might try
to distinguish whether a value was passed in for an optional parameter
or not (like the case Adam outlined). Relying on the value of the
optional parameter will not do, in that case (well it might, depending
upon how stringent you really need to be).


 That said, if you're making use of optional parameters and need to
 check if anything was passed in, you're almost certainly doing things
 wrong.

 Again, assuming you're talking about examples like the one above, I have
 to disagree. Presumably, passing in an optional parameter changes the
 action inside the function. Thus, you would *need* to test for its
 presence. Otherwise, you would be stuck with assuming it's there,
 attempting to use it on that assumption, and dealing with whatever
 errors it causes when-- surprise!-- it's not there.

You should be wary of assumptions, they're not really working out for you.
- a) you're not addressing Adam's use case
- b) I wouldn't need to test for any presence if I wrote the function
as I would personally prefer, i.e. not trying to test if any value was
passed to the function or not. That's the whole point of optional
values: even if nothing is passed in, there's a default value. That's
why trying to check if something was passed for the optional parameter
is counter-productive: the idea of the default value is that you
shouldn't have to check.

Regards
Peter

-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

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



Re: [PHP] Displaying Results

2011-02-15 Thread Peter Lind
On 15 February 2011 20:28, Ethan Rosenberg eth...@earthlink.net wrote:
 Dear List -

  I have a form.  In one field, the customer types the name of a product.
  The first seven(7) results of the MySQL query that the entry generates
 should be displayed as a clickable drop down list.

 How do I do it?

Ask google you should
Plenty of advice you'll find
we won't do your homework

Regards
Peter

-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

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



Re: [PHP] Re: First PHP site - thanks - euca_phpmysql function library

2011-02-09 Thread Peter Lind
On 9 February 2011 14:57, Bob McConnell r...@cbord.com wrote:
 From: Al

 On 2/8/2011 4:58 PM, Donovan Brooke wrote:
 Hello,

 Just wanted to say thanks to those that helped me get through my
 first PHP
 project (over the last month).

 As is with much of the work we server-side language people do, the
 back-end
 (non-public) side of this site is perhaps the more interesting.


 Suggestion: Design for XHTML 1.1.  It really doesn't require any
 significant
 additional effort and you'll already be current when it becomes the
 W3C
 standard. I like it because it forces me to create better, cleaner
 html code.

 You should also use the HTML Validator plug-in for Firefox to make sure
 you are producing valid XHTML. That makes it so much easier to find
 those invisible problems. I can't count how many times it has pointed
 right at a logic flaw in my code.

 Bob McConnell

Or go with the more likely candidate for a future html standard: html
5. Has the added benefit of easing you in to the new tags that will be
used as standard in a few years but won't be in xhtml.

Regards
Peter

-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

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



Re: [PHP] Re: First PHP site - thanks - euca_phpmysql function library

2011-02-09 Thread Peter Lind
On 9 February 2011 17:22, Bob McConnell r...@cbord.com wrote:
 From: Peter Lind

 On 9 February 2011 14:57, Bob McConnell r...@cbord.com wrote:
 From: Al

 On 2/8/2011 4:58 PM, Donovan Brooke wrote:
 Hello,

 Just wanted to say thanks to those that helped me get through my
 first PHP
 project (over the last month).

 As is with much of the work we server-side language people do, the
 back-end
 (non-public) side of this site is perhaps the more interesting.


 Suggestion: Design for XHTML 1.1.  It really doesn't require any
 significant
 additional effort and you'll already be current when it becomes the
 W3C
 standard. I like it because it forces me to create better, cleaner
 html code.

 You should also use the HTML Validator plug-in for Firefox to make sure
 you are producing valid XHTML. That makes it so much easier to find
 those invisible problems. I can't count how many times it has pointed
 right at a logic flaw in my code.

 Or go with the more likely candidate for a future html standard: html
 5. Has the added benefit of easing you in to the new tags that will be
 used as standard in a few years but won't be in xhtml.

 I don't believe HTML 5 will ever be completed. Microsoft is working hard 
 behind the scenes to block it unless it only allows their codec's behind the 
 video and canvas tags. (Their efforts are very reminiscent of their sabotage 
 of ISO with the OOXML specification.) From a recent announcement(*), it 
 appears that even the committee has given up ever having a usable consensus, 
 but will accept whatever the browser developers want to implement even if 
 they are incompatible with other browsers. That's not a standard.


Html 5 has a fair chance of not being completed (that's going by what
Ian Hickson has stated as well as reading blogs and such on the matter
- see http://en.wikipedia.org/wiki/HTML5 for a pointer or two). That's
besides the point, though: html 5 *is* where the web is headed, as
opposed to xhtml. In part this is happening by browsers implementing
features piece by piece as they become stable - hence, you can already
use some html 5 features and be rather certain they'll work as
expected later on. MS may hate things not working how they like it,
but big and stupid as they are they have in fact figured out that the
web will happily move on without them - so they'll get round to
implementing html 5 features as well, at some point, even if it
doesn't use their proprietary code.

Regards
Peter

-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

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



Re: [PHP] Bilingual strtotime()

2011-02-06 Thread Peter Lind
On Feb 6, 2011 11:16 AM, Per Jessen p...@computer.org wrote:

 Alexis wrote:

  I was wondering if there was a way to use the strtotime() function
  when the months are in one or the other of the above two languages?

 Ah, I misread this earlier - strtotime(), not strftime().  You're
 talking about transforming from text to a locale()-neutral format.  I
 don't think strtotime() is locale-sensitive - according to the manual:

 The function [strtotime] expects to be given a string containing an
 English date format




Strtotime can read a number of formats, but does (from experience) have
problems with some. It won't work with textual dates in anything but
English, far as I know.

Regards
Peter


Re: [PHP] No SMTP server? Can't get mail()

2011-01-20 Thread Peter Lind
Probably not the solution you were looking for, but I've always found mail()
very unstable and I tend to use a mail library instead. Like phpmailer or
swiftmailer. Easier to configure and figure out problems with.

Regards
Peter


Re: [PHP] Class and interface location

2011-01-19 Thread Peter Lind
How often would this profiling have to happen? Seems to me that if
it's a once per build or once per someone pressing the button,
then go for the more expensive analysis checking through the files.
Just build up a tree that shows which classes implement what or
inherit from where, save that along with file modification times, and
if you have to redo the analysis (on a running system, for instance)
then just check files that have changed since last check. It'll likely
be expensive once, but probably not very much (after all, you only
care about class, you don't need to parse docblocks or anything like
it).

regards
Peter
-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

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



Re: [PHP] email address syntax checker

2011-01-19 Thread Peter Lind
On 20 January 2011 05:14, Donovan Brooke li...@euca.us wrote:
 Hi Guys,

 I'm waddling my way through database interaction and thought someone on the
 list may already have a simple email checker that they'd like to share...

 you know, looking for the @ char and dots etc..

 I did a quick search of the archives and found a couple elaborate things..
 but
 I'm looking for something simple. This job will have trusted users and
 the checker is more to help them catch mistakes when registering.

if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
echo Bad user! Bad user!;
}

Regards
Peter

-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

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



Re: [PHP] Re: email list 101

2011-01-16 Thread Peter Lind
On 16 January 2011 16:35, Michelle Konzack
linux4miche...@tamay-dogan.net wrote:
 Hello Kirk Bailey,

 Am 2011-01-16 10:09:03, hacktest Du folgendes herunter:
 So, in php, I want a program to handle sending out a mail list. All
 this is going to do is be a filter to exclude non subscribers, and
 send a copy to every person in the subscriber file. This is pretty
 simple in python, but this is not my mother tounge we speak here, so
 let's talk in php instead.

 If the submission does not come from a member, the script simply
 aborts. So the script should read the subscriber file, and if the
 source From: does not appear there, DIE. If it is there, walk the
 array and send a copy there, then end.

 Now how to do this in php? Is there an off the shelf solution?

 Maybe using RTFW http://www.php.net/

Considering that you've used the PHP list for some very inane
questions yourself, perhaps you should keep the tone lighter and avoid
flaming people? Just a thought.

Regards
Peter

-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

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



[PHP] projectpier

2011-01-12 Thread Peter Lind
Heads up: jeg har flyttet projectpier over paa fastaval.dk domaenet -
det koerer nu under pp.fastaval.dk. Der er ogsaa sat redirects op paa
fastaval.plphp.dk saa man skulle ikke kunne komme til det gamle site
(og dermed ikke logge ind det forkerte sted).

-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

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



Re: [PHP] projectpier

2011-01-12 Thread Peter Lind
2011/1/12 Ashley Sheridan a...@ashleysheridan.co.uk

  On Wed, 2011-01-12 at 23:14 +0100, Peter Lind wrote:

 jeg har flyttet projectpier over paa fastaval.dk domaenet -
 det koerer nu under pp.fastaval.dk. Der er ogsaa sat redirects op paa
 fastaval.plphp.dk saa man skulle ikke kunne komme til det gamle site
 (og dermed ikke logge ind det forkerte sted)


 I think perhaps your change in domains was not meant to be posted to the
 list? :p


There's a massive ooops! if ever I did see one. Sorry about the (unintended)
noise and thanks for letting me know.


Re: [PHP] Re: First PHP job

2011-01-11 Thread Peter Lind
On Jan 11, 2011 4:32 PM, Gary php-gene...@garydjones.name wrote:

 Steve Staples wrote:
  or the ($needle, $haystack) vs ($haystack, $needle)... i still get it
  screwed up...

 Given that, for example, array_search and strstr take those arguments in
 different orders, that's not really surprising.


Something tells me that's what he meant ...


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



Re: [PHP] Re: Re: Re: PHP extension for equivalen of getent?

2011-01-08 Thread Peter Lind
On Jan 8, 2011 9:53 AM, David Robley robl...@aapt.net.au wrote:

 Michelle Konzack wrote:

  Hello David Robley,
 
  Am 2011-01-08 16:25:38, hacktest Du folgendes herunter:
  You might find http://xchm.sourceforge.net/ useful :-)
 
  [ 'apt-cache policy xchm' ]-
  xchm:
Installiert: 2:1.14-4
Kandidat: 2:1.14-4
Versions-Tabelle:
   *** 2:1.14-4 0
  900 ftp://ftp2.de.debian.org lenny/main Packages
  100 /var/lib/dpkg/status
  
 
  and it crash all the time...  :-(
 
  Thanks, Greetings and nice Day/Evening
  Michelle Konzack
 

 It's not Friday, so I won't go Off Topic and suggest you try compiling
from
 source :-)



While you're busy being not off topic, perhaps it might be an idea to also
not point to a proper place for questions about debian tools to read chm
files? I'm sure there are plenty of resources like irc channels or such.

Regards
Peter


Re: [PHP] Global or include?

2011-01-06 Thread Peter Lind
On Jan 6, 2011 4:24 PM, Sándor Tamás sandorta...@hostware.hu wrote:

  In that case you should use include_once in every script. But if you are
absolutely sure that all scripts will be processed, you can include it only
in one of them, because PHP - in short terms - does a file include, so it
will look like as the included file is part of the script.
 The global keyword does not do what you think, it only propagates
variables between functions without passing them as parameters. In general,
you ought to avoid using global, because it can make your script less
readable, and / or can lead to logical errors.

 Because I am OOP fan, I'd rather create a static class, using public
static fields, so you can reach those variable as like
ConstClass::MyConstant. In that way, you have the advantage of simply create
new constants, and it doesn't matter how many times you include this file,
there will be only one instance.

If you include the file several times, you still have the problem of
redeclaring the class, so you'd have to wrap the definition in a
conditional, which sucks, or use the *_once functions and incur the
overhead. Much better to be in control of the includes.

Apart from that, it's generally better to use require* instead of include*.
If the file is needed, don't continue without it, as the consequences will
be unknown.

 SanTa

 2011.01.05. 23:40 keltezéssel, Paul Halliday írta:

 Say you have 10 or so scripts and a single config file. If you have
 main.php, functions1.php, functions2.php, functions3.php..

 Does is hurt to do an include of the config file in each separate
 script, even if you only need a few things from it,  or should you
 just specify what you want with a 'global' within each
 script/function?

 Thanks!




Re: [PHP] memory usage/release GC

2010-12-31 Thread Peter Lind
On Dec 31, 2010 6:20 AM, Tommy Pham tommy...@gmail.com wrote:

 Hi folks,

 With the recent thread about password  security, I wrote a small quick
 script to generate a random or all possible passwords based on certain
 parameters for a brute force use.  On a very long running execution for a
 complex password in length with full use of the keys (94 characters),
 including upper case, the script seems to consumes more memory (shown in
 Windows task manager) as time progress.  Below are snippets from the
script
 file that does the workload:

 while (!$this-isMax())
 {
for ($b = 0; $b = $this-pwdLength; $b++)
{
if ($this-counter[$b]  $this-max)
{
$this-pwd[$b] =
 $this-charList[$this-counter[$b]];
$this-counter[$b]++;
break;
}
else
{
$this-counter[$b] = 1;
$this-pwd[$b] = $this-charList[0];
}
}
 }

 private function isMax()
 {
for ($a = $this-pwdLength-1; $a=0; $a--)
{
if ($this-counter[$a]  $this-max) return false;
}
return true;
 }

 Could someone please tell me why the above code consumes additional memory
 as time progress for the execution of the while loop?  Researching PHP GC
on
 google didn't shed light on problem.  Generating all possible combinations
 for 20 length with 94 possibilities each, the script easily consumes more
 than 1GB RAM in few minutes.  BTW, gc_enabled() reports on.

 Thanks,
 Tommy



Are you storing or throwing away the passwords? Also, lots of code is
missing from that post, no idea if you've got a memory leak in the rest of
the code

Regards
Peter


Re: [PHP] Re: Do you trim() usernames and passwords?

2010-12-28 Thread Peter Lind
On 28 December 2010 21:18, Dotan Cohen dotanco...@gmail.com wrote:
 On Tue, Dec 28, 2010 at 21:57, Nathan Rixham nrix...@gmail.com wrote:
 Don't trim or limit the range of input characters, but far more importantly
 /don't send passwords in clear text/, indeed don't generate passwords at
 all, let users enter there desired password, then they won't be copy and
 pasting them ;)

 ps: if unavoidable, then give some advice on login failure like passwords
 are case sensitive, check you don't have caps lock on and that you haven't
 included any additional spaces.


 I'm toying with the idea of having the passwords hashed twice: they're
 already in the database hashed, and javascript hashes them on the
 client before sending them over, but I'm thinking about sending an
 additional salt to the client to hash the hashed passwords with salt,
 and that's what is sent back. This way, each login is done with a
 different hash of the password so an attacker cannot simply capture
 and reuse the hashed password.

Sounds like https would be MUCH simpler and likely as safe or safer. I
wouldn't waste my time on trying to come up with very clever schemes
when tried and true technologies are out there.

 But before all that goes on, I have to decide what to do about leading
 and trailing spaces.

As has been noted a couple of times: trim usernames. Never trim passwords.

Regards
Peter

-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

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



Re: [PHP] Re: Do you trim() usernames and passwords?

2010-12-28 Thread Peter Lind
On 28 December 2010 22:06, Daniel Brown danbr...@php.net wrote:
 On Tue, Dec 28, 2010 at 16:05, Dotan Cohen dotanco...@gmail.com wrote:

 Did you know that when you type 'brown1' we see it as **? Your
 system does that automatically.

    That's how I see it, too.  It took me fourteen years to realize
 that my password wasn't just six asterisks (though, in my hand-made,
 high-security login scripts, the same will work, in case I forget my
 password).


Bla bla bla not Friday yet bla bla bla cut down on the noise on the list bla bla


-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

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



Re: [PHP] How to define a data range for graphing?

2010-12-17 Thread Peter Lind
On Friday, 17 December 2010, Simon J Welsh si...@welsh.co.nz wrote:
 On 18/12/2010, at 8:45 AM, Brian Dunning wrote:

 Hey all -

 I'm trying to provide reporting to users of our widget. Some may get 0 to 5 
 hits a day; others may get up to 10,000 hits a day. I need to define the 
 range of the graph (using one of Google's). If their max day is 7, I'd like 
 the graph to go from 0 to 10. If their max day is 5678, I'd probably like it 
 to go from 0 to 6000. I'm guessing the way to do this is with a ceiling 
 function?

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


 Personally, I'd use something like:

 if($hits  10) {
         $top = 10;
 } else {
         $top = ($hits[0] + 1) * pow(10, strlen($hits) - 1);
 }

 Basically, add one to the first digit and make the rest of the digits 0. 
 Depending on how you want to handle the cases ending in 0s, you may want an 
 extra check in there.

 General disclaimer about code typed directly into mail client.

 Happy Saturday :)

Personally I'd add a percentage on top, say 5 or 10 percent.

Regards
Peter

-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

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



Re: [PHP] ORM doctrine

2010-12-12 Thread Peter Lind
 I understand cache well, both the benefits (save DB trip) and shortfalls 
 (outdated by DB, management, etc.).  Most of the apps that I've seen so far 
 used cache to solve a problem that shouldn't happen in the 1st place.  For 
 example, during recent my quest looking PHP MVC framework and sample apps, I 
 saw OpenCart, an e-commerce app based on custom MVC framework.  Installed it 
 for a test run.  It looks good and seems to perform well with the included 
 sample data.  Then I filled up some more sample data: over 3000 categories, 
 over 2000 manufacturers, over 300,000 products.  No other changes made such 
 specials, features, etc.  Although the app supports i18n, the sample data is 
 just one language for a decent DB size of about 100MB.  The app took over 30 
 seconds to respond for any link.  Then I disable the cache and began 
 debugging.  I made 1 minor addition to the DB and 1 minor change in the code 
 base - parts on 1 line - I shorten the response time by about 10 seconds.  
 What I just did proved my 2nd and 3rd point :)

 Regards,
 Tommy


An app that takes 30 secs to respond using cache is doing it wrong.
You shaving 10 secs off the request without cache is fine but you
should have brought it much further down with a cache. Waiting 20 secs
for the response is still useless.

Regards
Peter

-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

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



Re: [PHP] ORM doctrine

2010-12-12 Thread Peter Lind
On Sunday, 12 December 2010, Tommy Pham tommy...@gmail.com wrote:
 -Original Message-
 From: Peter Lind [mailto:peter.e.l...@gmail.com]
 Sent: Sunday, December 12, 2010 1:18 AM
 To: Tommy Pham
 Cc: php-general List
 Subject: Re: [PHP] ORM doctrine

  I understand cache well, both the benefits (save DB trip) and
  shortfalls (outdated by DB, management, etc.).  Most of the apps that
  I've seen so far used cache to solve a problem that shouldn't happen
  in the 1st place.  For example, during recent my quest looking PHP MVC
  framework and sample apps, I saw OpenCart, an e-commerce app based
 on
  custom MVC framework.  Installed it for a test run.  It looks good and
  seems to perform well with the included sample data.  Then I filled up
  some more sample data: over 3000 categories, over 2000 manufacturers,
  over 300,000 products.  No other changes made such specials, features,
  etc.  Although the app supports i18n, the sample data is just one
  language for a decent DB size of about 100MB.  The app took over 30
  seconds to respond for any link.  Then I disable the cache and began
  debugging.  I made 1 minor addition to the DB and 1 minor change in
  the code base - parts on 1 line - I shorten the response time by about
  10 seconds.  What I just did proved my 2nd and 3rd point :)
 
  Regards,
  Tommy
 

 An app that takes 30 secs to respond using cache is doing it wrong.
 You shaving 10 secs off the request without cache is fine but you should
 have brought it much further down with a cache. Waiting 20 secs for the
 response is still useless.

 Regards
 Peter

 --
 hype
 WWW: plphp.dk / plind.dk
 LinkedIn: plind
 BeWelcome/Couchsurfing: Fake51
 Twitter: kafe15
 /hype

 My goal wasn't to optimize any app.  I just want to learn 'implement abstract 
 MVC concept into concrete, ...' as I mentioned in Adam's thread about 
 choosing framework or not.  If I was to optimize it, I wouldn't have any 
 problems lowering the response time down to under 3 seconds w/o cache.

 Regards,
 Tommy


Your posts seem to indicate that caches are only useful when other
parts of the app have been done wrong. My point was that this is a
fairly fundamental misunderstanding of caches - regardless of what you
are or aren't capable of optimizing.

Regards
Peter

-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

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



Re: [PHP] ORM doctrine

2010-12-12 Thread Peter Lind
On Sunday, 12 December 2010, Tommy Pham tommy...@gmail.com wrote:
 -Original Message-
 From: Lester Caine [mailto:les...@lsces.co.uk]
 Sent: Sunday, December 12, 2010 2:10 AM
 To: php-general List
 Subject: Re: [PHP] ORM doctrine

 Peter Lind wrote:
  Your posts seem to indicate that caches are only useful when other
  parts of the app have been done wrong. My point was that this is a
  fairly fundamental misunderstanding of caches - regardless of what you
  are or aren't capable of optimizing.

 CHACHES are only useful when there are static views of the information
 available. Only static elements can be cached with any real chance of
 performance improvement, so part of what Tommy is saying is correct.
 Although the way he has worded that is perhaps a little misleading?

Possibly. However, thinking that a cache is something you apply at the
end of development means you may well bar yourself from better uses of
one. Ie. thinking that a cache is icing on the cake prohibits you
from mixing it into the cake (to further abuse a metaphor) which
could give you a better recipe.
 I may have misunderstood the topic, but a cache to me is more than
just storing views. It's also the db cache, memcache, apc, etc. You
have to think about how you use these - some of them can't just be
slapped on to your app after development.


 Data caching SHOULD always be the
 domain of the database, so duplicating that in PHP is pintless.

So you're saying one should never use memcache for storing data from the db?

Regards
Peter

-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

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



Re: [PHP] ORM doctrine

2010-12-12 Thread Peter Lind
On Sunday, 12 December 2010, Tommy Pham tommy...@gmail.com wrote:
 -Original Message-
 From: Lester Caine [mailto:les...@lsces.co.uk]
 Sent: Sunday, December 12, 2010 2:10 AM
 To: php-general List
 Subject: Re: [PHP] ORM doctrine

 Peter Lind wrote:
  Your posts seem to indicate that caches are only useful when other
  parts of the app have been done wrong. My point was that this is a
  fairly fundamental misunderstanding of caches - regardless of what you
  are or aren't capable of optimizing.

 CHACHES are only useful when there are static views of the information
 available. Only static elements can be cached with any real chance of
 performance improvement, so part of what Tommy is saying is correct.
 Although the way he has worded that is perhaps a little misleading?

Possibly. However, thinking that a cache is something you apply at the
end of development means you may well bar yourself from better uses of
one. Ie. thinking that a cache is icing on the cake prohibits you
from mixing it into the cake (to further abuse a metaphor) which
could give you a better recipe.
 I may have misunderstood the topic, but a cache to me is more than
just storing views. It's also the db cache, memcache, apc, etc. You
have to think about how you use these - some of them can't just be
slapped on to your app after development.


 Data caching SHOULD always be the
 domain of the database, so duplicating that in PHP is pintless.

So you're saying one should never use memcache for storing data from the db?

Regards
Peter

-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

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



Re: [PHP] ORM doctrine

2010-12-12 Thread Peter Lind
On Sunday, 12 December 2010, Lester Caine les...@lsces.co.uk wrote:
 Peter Lind wrote:

 I may have misunderstood the topic, but a cache to me is more than
 just storing views. It's also the db cache, memcache, apc, etc. You
 have to think about how you use these - some of them can't just be
 slapped on to your app after development.


  Data caching SHOULD always be the
  domain of the database, so duplicating that in PHP is pintless.



 So you're saying one should never use memcache for storing data from the db?


 That is probably one of the areas where care should be taken in WHAT you are 
 caching. CURRENTLY too much caching goes on

I have not seen this problem but I have often seen sites not caching
things they should, so I'd say you're wrong. I don't think its
relevant one way or the other though.

 memcache may well be a candidate to use for a cached list of choices for a 
 form, but on a distributed database ( such as Firebird ) then how do you KNOW 
 if the list has been updated?

This is relevant to very few developers. Much more relevant is the
overhead used in contacting the single mysql/postgresql/etc database
that your provider put on another machine.

 Only the database actually knows that, and a good database will provide ALL 
 of the data caching that you need ... or at least it should if the DATABASE 
 is designed correctly.

See above.

 The reason for 'caching' needs to be understood before it is applied in order 
 to avoid the black holes that random caching is causing nowadays already. How 
 often do you hear wipe the xxx browser cache? And I know if I am changing 
 theme elements in bitweaver or phpgedview then I HAVE to wipe the cache to 
 ensure that smarty rebuilds the relevant pages.

Which underlines my point: caching is not icing on the cake but should
be thought of sooner in the process, contrary to Tommys point.

Regards
Peter

-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

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



Re: [PHP] ORM doctrine

2010-12-11 Thread Peter Lind
On Friday, 10 December 2010, Tommy Pham tommy...@gmail.com wrote:

* snup *

 The way I see it is this:

 1) Thorough understanding of the problem: needs of the client/company,
 programming language in use, etc.
 2) Thorough understanding of the objective of the application: answer the
 needs, capable of possible future growth/expandability, etc.
 3) Well thought out application design to resolve the above 2:  framework,
 mixed, or no framework.

 Thus, IMHO, caching is needed when one fails to fully meet the above 3 such
 as when the user clicks on any link in the browser, it should take no more
 than 3 seconds for the browser's status to be 'Done', provided that the user
 isn't on some 56k modem connection ;).

Always use a cache. Not using a cache means you've misunderstood some
fundamental points.

Regards
Peter


-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

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



Re: [PHP] php mail() and sendmail/smtp

2010-12-02 Thread Peter Lind
2010/12/2 Michael Crowl octo...@serv.net:

* snip *

 Also, we
 have Redmine running on the same server, and it sends admin emails out just
 fine - however, I don't think it calls sendmail directly like our PHP
 install, but connects directly to the local SMTP server.

Sounds like a solution to me: connect to port 25 on the mail server
instead of going through sendmail. Plenty of good mail libraries out
there (swiftmailer, phpmailer come to mind).

Regards
Peter

-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

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



Re: [PHP] PHP Add +1 mysql updates by 2?

2010-11-26 Thread Peter Lind
On Saturday, November 27, 2010, Richard West p...@cbnisp.com wrote:
 Hey Tommy,

 I get the same when seting it to a_downloads=a_downloads+1
 It still increments by 2
 I've never run into this before.
 RD


 On Nov 26, 2010, at 11:45 PM, Tommy Pham wrote:

 -Original Message-
 From: Tamara Temple [mailto:tamouse.li...@gmail.com]
 Sent: Friday, November 26, 2010 7:54 PM
 To: Richard West
 Cc: PHP General Mailing List
 Subject: Re: [PHP] PHP Add +1 mysql updates by 2?


 On Nov 26, 2010, at 8:36 PM, Richard West wrote:

 Hey guys,
 I've never run into this before.
 I have a field in mysql for page views.
 So I pull out value and do +1 to new value - after UPDATE SET it has
 incremented by 2?

 $val = $row['a_downloads'] ;

 $new_val = $val+1;

 mysql_query(UPDATE cbn_articles SET a_downloads='$new_val' WHERE
 a_id
 = '.$_GET['id'].' );

 Any ideas? What am I missing?
 RD

 a_downloads wouldn't happen to be an autoincrement value, would it?


 IIRC, the auto_increment should only increment on an INSERT statement and
 the field is omitted.  Besides, in MySQL, auto_increment must also be part
 of the primary key.  From Richard's query, I'd say that his primary key
 field is most likely a_id.  IMO, the best way to count something is to set
 the field to an int(eger) type.  Then just run 'UPDATE table_name SET
 count_field = count_field +1 WHERE criteria_column =  $criteria'.  This is
 more safe as you many have simultaneous users downloading.  This would
 ensure an accurate count, whereas your logic wouldn't.

 Regards,
 Tommy

 PS:  Richard, you should validate and sanitize all inputs.  Your query is
 prone to injection attack (deletion of rows or your entire DB deleted).  Use
 either mysql_escape_string or, better yet, mysqli to prepare the statement
 and bind the parameters.



Sounds like you're hitting the page twice. Check for missing image,
css files, favicons, js files etc.

-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

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



Re: [PHP] PHP Add +1 mysql updates by 2?

2010-11-26 Thread Peter Lind
And what difference will that make if the document is requested twice with
every browser load?
On Nov 27, 2010 6:39 AM, Richard West p...@cbnisp.com wrote:
 I took that into consideration so I added the update at the very end of
document...
 Still the same,
 RD




 On Nov 27, 2010, at 12:31 AM, Peter Lind wrote:

 On Saturday, November 27, 2010, Richard West p...@cbnisp.com wrote:
 Hey Tommy,

 I get the same when seting it to a_downloads=a_downloads+1
 It still increments by 2
 I've never run into this before.
 RD


 On Nov 26, 2010, at 11:45 PM, Tommy Pham wrote:

 -Original Message-
 From: Tamara Temple [mailto:tamouse.li...@gmail.com]
 Sent: Friday, November 26, 2010 7:54 PM
 To: Richard West
 Cc: PHP General Mailing List
 Subject: Re: [PHP] PHP Add +1 mysql updates by 2?


 On Nov 26, 2010, at 8:36 PM, Richard West wrote:

 Hey guys,
 I've never run into this before.
 I have a field in mysql for page views.
 So I pull out value and do +1 to new value - after UPDATE SET it has
 incremented by 2?

 $val = $row['a_downloads'] ;

 $new_val = $val+1;

 mysql_query(UPDATE cbn_articles SET a_downloads='$new_val' WHERE
 a_id
 = '.$_GET['id'].' );

 Any ideas? What am I missing?
 RD

 a_downloads wouldn't happen to be an autoincrement value, would it?


 IIRC, the auto_increment should only increment on an INSERT statement
and
 the field is omitted. Besides, in MySQL, auto_increment must also be
part
 of the primary key. From Richard's query, I'd say that his primary key
 field is most likely a_id. IMO, the best way to count something is to
set
 the field to an int(eger) type. Then just run 'UPDATE table_name SET
 count_field = count_field +1 WHERE criteria_column = $criteria'. This
is
 more safe as you many have simultaneous users downloading. This would
 ensure an accurate count, whereas your logic wouldn't.

 Regards,
 Tommy

 PS: Richard, you should validate and sanitize all inputs. Your query is
 prone to injection attack (deletion of rows or your entire DB deleted).
Use
 either mysql_escape_string or, better yet, mysqli to prepare the
statement
 and bind the parameters.



 Sounds like you're hitting the page twice. Check for missing image,
 css files, favicons, js files etc.

 --
 hype
 WWW: plphp.dk / plind.dk
 LinkedIn: plind
 BeWelcome/Couchsurfing: Fake51
 Twitter: kafe15
 /hype



Re: [PHP] is this thing on??

2010-11-23 Thread Peter Lind
On 23 November 2010 20:52, Steve Staples sstap...@mnsi.net wrote:
 tap tap tap... testing testing... 1, 2, 3

 Hello?    No activity since yesterday at like 6pm EST... am i not
 getting messages, or has there not been any activity?

 Just curious... carry on about your business... :P


http://news.php.net/php.general - please, next time, don't spam tons of people.

-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

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



Re: [PHP] Procedural Autoloader?

2010-11-22 Thread Peter Lind
On 22 November 2010 22:40, Daniel P. Brown daniel.br...@parasane.net wrote:
 On Mon, Nov 22, 2010 at 16:31, Nathan Nobbe quickshif...@gmail.com wrote:

 Shrug, if you want to really be dirty about it, you could just put a 'class'
 atop each file of functions.
 ?php
 class IWishTheseFunctionsWereOOInstead {} // :P
 function firstProceeduralFunc() {
  // ..
 }
 ?

    That's not going to be economical or allow him to autoload,
 though, because the autoloader is called when the class is
 instantiated.

Not to mention that it has nothing to do with a procedural autoloader.
Autoloading takes place if you try to instantiate an object of a class
that PHP doesn't know about (yet). There is no such thing for
functions. Either refactor your code so you don't have this problem
(The Way To Go [tm]) or make an extension. End of discussion.

Regards
Peter

-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

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



Re: [PHP] DOMDocument/DOMElement problem

2010-11-17 Thread Peter Lind
On 16 November 2010 21:30, Adam Richardson simples...@gmail.com wrote:
 Hmmm...

 Nothing really stands out to me, but as my wife would attest, I'm often less
 than observant.

 I would probably try sifting through fixes/upgrades in the change logs for
 possible conflicts and/or changes in behavior.  Nothing jumped out at me
 after a quick glance.

 Sorry,

 Adam


Thanks for having a look. Far as I can tell, the main problem was
related to the encoding of the input data - and as such, the problem
was as likely to be in libxml as in php. I haven't seen any updates to
the DOM* extensions that would explain the change in behaviour and
really find it weird - but, at least I found a solution to the
problems :)

Quick note, in case anyone has similar problems: make sure that the
data you feed into DOMDocument is UTF8 encoded

Regards
Peter

-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

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



[PHP] DOMDocument/DOMElement problem

2010-11-16 Thread Peter Lind
I'm currently trying to parse a document with DOMDocument, and I'm
having some serious problems. I created a script that runs fine on php
5.2.9, ripping out content using DOMNode::nodeValue. The same script
fails to get any content on php 5.3.3 - even though it correctly
navigates to the proper nodes to extract content.

Basically, the code used looks like this:

$dom = new DOMDocument();
$dom-loadHTML($data);
$dom-preserveWhiteSpace = false;
$xpath = new DOMXpath($dom);
$nodelist = $xpath-query($query);
$value = $nodelist-item(0)-nodeValue;

I've checked to make sure that item(0) is in fact a node - it's there
and even of the right type (a td - table cell), but nodeValue is
empty.

The script works on some documents but not others (on 5.3.3 - some
checking suggests a doctype of xhtml might be involved in the problem
but I tried ripping the doctype out and had no difference) - on 5.2.9
it works on all documents, returning the proper nodeValue.

Am I missing something basic?

TIA
Peter

-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

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



Re: [PHP] Template engines

2010-11-08 Thread Peter Lind
On 8 November 2010 22:59, Michael Shadle mike...@gmail.com wrote:
 On Mon, Nov 8, 2010 at 1:41 PM, Hansen, Mike mike.han...@atmel.com wrote:
 I really like the idea of using a templating engine. Which one do you use? 
 Why? For those that don't use templating engines, why don't you use them?

 smarty is everyone's favorite usually but i find it a bit annoying.

 not to mention php itself is already a templating language... the only
 benefit is trying to separate content and presentation.

 however, for that to happen people create DSLs for templating that all
 have their own little syntaxes and glitches and annoyances.


PHPTal is an alternative to smarty: http://phptal.org/ - it's got a
nice syntax, I find.

However, whether one should bother with a templating system like
smarty or phptal very much depends upon how intricate your front-end
system needs to be and what it needs to do. For smaller projects.
smarty or phptal will get in the way and will likely get very
annoying. For bigger projects they can be of great use.

Regards
Peter

-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

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



Re: [PHP] Template engines

2010-11-08 Thread Peter Lind
On 9 November 2010 06:20, Paul M Foster pa...@quillandmouse.com wrote:
 On Mon, Nov 08, 2010 at 02:41:12PM -0700, Hansen, Mike wrote:

 I really like the idea of using a templating engine. Which one do you
 use? Why? For those that don't use templating engines, why don't you
 use them?


 Here's why I don't use a templating engine.

 First, You're taking an embedded language and writing a templating
 engine in it. Seriously?

 Second, you're painting a single page, maybe 10-15K worth of
 information, and you're dragging 100K of code around just to paint a
 single page. Seriously?

 Third, you're creating a page on the fly, thrashing the server's CPU in
 order to generate a page which could be built statically, or at least
 with minimally embedded PHP. Seriously?


You assume that the OP will either make static pages (yet posts on the
PHP mailing list) or makes pages that aren't very dynamic in any
sense. Seriously?


-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

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



Re: [PHP] include() and duplicate function definition

2010-11-03 Thread Peter Lind
You can check with function_exists to see if a function is already defined.
If not, create it.

Regards
Peter
On Nov 3, 2010 11:40 AM, David Nelson comme...@traduction.biz wrote:
 Hi Thijs, :-)

 On Wed, Nov 3, 2010 at 18:18, Thijs Lensselink d...@lenss.nl wrote:
 As far as I know it is not possible to overwrite functions in PHP (unless
 you use runkit, apd). Inside classes this is possible. But that's not the
 case here. Why do the functions have to be equally named?

 If the functions aren't named the same, my replacement function will
 never get called by the code that uses the WordPress theme code...

 Try to create a new function and call the original function from there if
 needed...

 Sadly, it wouldn't work for the above reason...

 But thanks for your answer. :-)

 David Nelson

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



Re: [PHP] include() and duplicate function definition

2010-11-03 Thread Peter Lind
That's not going to happen. My point was you could check in the original
file if the function is defined and if not then define it.
On Nov 3, 2010 11:55 AM, David Nelson comme...@traduction.biz wrote:
 Hi Peter, :-)

 On Wed, Nov 3, 2010 at 18:44, Peter Lind peter.e.l...@gmail.com wrote:
 You can check with function_exists to see if a function is already
defined.
 If not, create it.

 The function is definitely already defined, I just need to replace it
 without touching the file in which it's defined...

 David Nelson


Re: [PHP] I need some thoughts on code duplication and separation

2010-10-21 Thread Peter Lind
On 21 October 2010 04:59, David McGlone da...@dmcentral.net wrote:
 On Thu, 2010-10-21 at 04:05 +0200, Rico Secada wrote:
 Hi.

 I am working on a small system where I am both trying to avoid code
 duplication and at the same time I am trying to keep the presentation
 logic separated from the application logic.

 I am using sessions and are avoiding headers already sent problem by
 keeping the HTML out of the application.

 For example, I would like to have a common header.php file, but it is
 difficult to create this since one file needs to have some specific
 Javascript located in the head /head tags, but the other files
 doesn't need this.

 Another file needs to have a specific onload call in the body tag,
 while yet another file also needs to have an onload call, but with
 different attributes.

 I have been looking around in other systems to see what kinds of
 solutions are being used - as inspiration.

 I have been thinking about the following solutions:

 1. Create only ONE header.php file that contains a lot of conditionals
 depending on what file is including it - the output of HTML/Javascript
 changes.

 I believe this would turn into a very ugly hack. Difficult to maintain.

 2. Create a HTML generating class with a set of methods that each
 contains an adequate amount of parameters. Each method maintains its
 own HTML tag. For example, docType($type) would generate the doctype
 specification.

 I believe this is a cleaner solution, but the problem with code
 duplication isn't avoided.

 Some of the presentation logic contains conditionals and the HTML
 changes when the conditional changes, hence the header content changes,
 but the doctype, html, and head doesn't necessarily change and
 they would get duplicated a couple of times in some files.

 3. Avoid the problem all together, use output buffering and completely
 forget about separation between application and presentation.

 I hope I make sense.

 Any thoughts on these kinds of problems?

 sounds like a job for smarty http://www.smarty.net/

 I've used smarty and it's nice.


How does Smarty solve this problem? Just curious.

Regards
Peter

-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

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



Re: [PHP] Reminder On Mailing List Rules

2010-10-21 Thread Peter Lind
On 21 October 2010 16:25, Daniel Brown danbr...@php.net wrote:

* snip *

    The ultimate goal here isn't to start a flame war (or even any
 further discussion on the subject for that matter), but to point out
 that this is a RULE of the official community here, not a PREFERENCE.


If only the thread had ended there ...

Regards
Peter

-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

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



Re: [PHP] Re: Buffering output to allow headers late in code?

2010-10-14 Thread Peter Lind
Just out of curiosity: why were you told to switch off output buffering?

Regards
Peter

-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

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



Re: [PHP] which one is faster

2010-10-06 Thread Peter Lind
On 6 October 2010 14:40, Bob McConnell r...@cbord.com wrote:
 From: Steve Staples

 On Tue, 2010-10-05 at 20:53 +0100, Ashley Sheridan wrote:
 On Tue, 2010-10-05 at 15:46 -0400, Steve Staples wrote:

  On Tue, 2010-10-05 at 20:35 +0100, Ashley Sheridan wrote:
   On Tue, 2010-10-05 at 15:28 -0400, chris h wrote:
  
Benchmark and find out! :)
   
What are you using this for? Unless you are doing something
 crazy it
probably doesn't matter, and you should pick whichever you feel
 looks nicer
/ is easier to code in / etc.
   
Chris H.
   
On Tue, Oct 5, 2010 at 3:23 PM, saeed ahmed
 saeed@gmail.com wrote:
   
 $a = 'hey';
 $b = 'done';

 $c = $a.$b;
 $c = $a$b;

 which one is faster for echo $c.

  
  
   As far as I'm aware, the first of the two will be faster, but
 only just.
   As Saeed mentioned, the difference will be negligible, and unless
 you
   plan to run a line like that in a loop or something hundreds of
   thousands of times, you probably won't notice any difference.
   Thanks,
   Ash
   http://www.ashleysheridan.co.uk
 
  to be proper, shouldn't it technically be
  $c = {$a}{$b};
 

 It doesn't have to use the braces. The braces only tell PHP exactly
 where to stop parsing the current variable name. The following
 examples
 wouldn't work without them:

 $var = 'hello ';
 $arr = array('msg 1'='hello','msg 2'='world');

 echo {$var}world;
 echo {$arr['msg 1']}{$arr['msg 2']};

 Without the braces, in the first example PHP would look for a
 variable
 called $varworld, and in the second it would be looking for a simple
 scaler called $arr, not the array value you wanted.

 Ash:

 I understand what the {} does, but just like in HTML, it is more
 proper
 to use lower case for the attributes/elements, and use  (double
 quotes)
 when wrapping the attributes... but is it not REQUIRED to write it
 in
 that manner... just like it is not required to wrap the variables in
 {}
 when inside the ...

 that's just me, I tend to try and do that every time...

 XHTML requires both lower case and double quotes. So if that may be in
 your future, you should be using both already.

 I don't know about HTML 5. Since that spec is still years away from
 completion and hasn't added anything we can make use of, we haven't even
 bothered to look at it.


Where exactly do you get the part about double quotes from? Can't seem
to locate it in the any of the relevant specs (xhtml or xml). Also,
never seen an xml or xhtml validator choke on single quotes.

As for html 5, it's in use today already. Big parts of it are unlikely
to change, so there's little reason not to start using it.

Regards
Peter

-- 
hype
WWW: http://plphp.dk / http://plind.dk
LinkedIn: http://www.linkedin.com/in/plind
BeWelcome/Couchsurfing: Fake51
Twitter: http://twitter.com/kafe15
/hype

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



Re: [PHP] which one is faster

2010-10-06 Thread Peter Lind
On 6 October 2010 15:31, Andy McKenzie amckenz...@gmail.com wrote:

*snip*

 Double quotes are the only example given:  in most documentation if
 there are two allowed forms, there are two examples, or at least a
 note in the text.  I haven't read enough of this particular document
 to know if they follow that form, but I've certainly seen it a lot of
 places.

 -Alex


Xhtml documents are xml documents and thus must follow the specs for
XML. Specifically, the following:
http://www.w3.org/TR/2008/REC-xml-20081126/#NT-AttValue

Regards
Peter

-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

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



Re: [PHP] New to PHP and struggling with the basics

2010-10-04 Thread Peter Lind
On 4 October 2010 11:30, Col Day colind...@aol.com wrote:
 Hi all,

 Working with the PHP5 for Dummies book (yup real noob, feel free to ridicule
 (after telling me what I've done wrong)) and have installed Apache 2.2 and
 PHP 5.3.3 onto a laptop running Vista. (yes I know!!!).

 I've had Apache running fine with my basic web site created using Serif's
 Webplus10 but wanted to experiment with PHP as I want an uploadable area on
 my website for my friends and family to submit video/photos.

 I've checked the install of PHP using php -v and I get the output that

 PHP 5.3.3 (cli) (built: Jul 21 2010 20:10:20)

 but when I try and go to the test.php file (below) I get an http 403 webiste
 requires you to log in. Error message.

 html
 head
 titlePHP Test/title
 /head
 body
 pThis is an HTML line
 ?php
 echo pThis is a PHP line/p;
 phpinfo();
 ?
 /body
 /html

 This is the text of the test.php file which I have plonked down in
 /apache/htdocs

 What have I missed?

 the Dummies book is quoting PHP 5.0.0 as the latest release so not too far
 away really.


A) v5.0.0 is years old. B) your issue is with apache, not php - 403 is
a you have no permission to see this.

Check permissions for the file you're trying to test, as well as for
the folder. Also, seeing as you're naming the file test.php, make sure
you're browsing for that file and not just / or index.php.

Regards
Peter

-- 
hype
WWW: http://plphp.dk / http://plind.dk
LinkedIn: http://www.linkedin.com/in/plind
BeWelcome/Couchsurfing: Fake51
Twitter: http://twitter.com/kafe15
/hype

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



Re: [PHP] Re: Friday's Post

2010-10-02 Thread Peter Lind
On 1 October 2010 20:21, Per Jessen p...@computer.org wrote:
 Peter Lind wrote:

 C# has by now exceeded Java by quite a bit -

 I've been away from the Java scene since 2002 (when I worked for BEA
 deploying J2EE on Linux/390), but assuming you're talking
 about deployed lines of code or some other real-life measurement, I
 find it hard to believe that C# should have exceeded Java.

Language functionality. I'd much rather use C# than Java as I can do
more in C# and easier than with Java. For instance, C# 4 has  support
for late binding to dynamic types. Does Java have an equivalent? Is
it planned?

Regards
Peter

-- 
hype
WWW: http://plphp.dk / http://plind.dk
LinkedIn: http://www.linkedin.com/in/plind
BeWelcome/Couchsurfing: Fake51
Twitter: http://twitter.com/kafe15
/hype

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



Re: [PHP] Re: Friday's Post

2010-10-02 Thread Peter Lind
On 2 October 2010 11:05, Per Jessen p...@computer.org wrote:
 Peter Lind wrote:

 On 1 October 2010 20:21, Per Jessen p...@computer.org wrote:
 Peter Lind wrote:

 C# has by now exceeded Java by quite a bit -

 I've been away from the Java scene since 2002 (when I worked for
 BEA deploying J2EE on Linux/390), but assuming you're talking
 about deployed lines of code or some other real-life measurement, I
 find it hard to believe that C# should have exceeded Java.

 Language functionality. I'd much rather use C# than Java as I can do
 more in C# and easier than with Java. For instance, C# 4 has  support
 for late binding to dynamic types. Does Java have an equivalent? Is
 it planned?

 I don't know, but Java obviously supports late binding.


I was looking more for dynamic types, much more of interest to the
average PHP dev as that's one of the typical stumbling blocks when
switching languages. And no, far as I can tell Java doesn't offer
that.

Regards
Peter

-- 
hype
WWW: http://plphp.dk / http://plind.dk
LinkedIn: http://www.linkedin.com/in/plind
BeWelcome/Couchsurfing: Fake51
Twitter: http://twitter.com/kafe15
/hype

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



Re: [PHP] Re: Friday's Post

2010-10-01 Thread Peter Lind
On 1 October 2010 17:11, Bob McConnell r...@cbord.com wrote:
 From: Gary

 tedd wrote:
 What do you people think of the .NET framework?

 It's a framework, like any other framework - can make your life
 easier,
 can make your life harder by forcing you to take the path determined
 as
 TOTP by its designers.

 That's The One True Path, not Top Of The Pops.

 The installer and the license limit its use to just a subset of a single
 platform. The attempts at producing clones on other platforms are
 clouded by license and patent restrictions, and will perpetually be at
 least one release behind the MS-Windows version.

 In reality, .Net is a poor clone of the Java runtime environment, while
 C# is a poor clone of the Java language. They were created after the
 courts told Microsoft the Sun license did not allow them to subvert the
 Java API to build applications that would only run on their OS.


C# has by now exceeded Java by quite a bit - and is, unlike Java, very
actively maintained and has fairly frequent releases with lots of new
functionality (4.0 was released this year and has functionality that
definitely makes me consider taking it on).

As for whether .Net is a better library than the JVM, I wouldn't be
able to judge that.

Regards
Peter

-- 
hype
WWW: http://plphp.dk / http://plind.dk
LinkedIn: http://www.linkedin.com/in/plind
BeWelcome/Couchsurfing: Fake51
Twitter: http://twitter.com/kafe15
/hype

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



Re: [PHP] Heredocs, print_r() and newline \n and fnmatch() -curious failures ...

2010-09-27 Thread Peter Lind
On 24 September 2010 12:49, YAD(YetAnotherDavid) ani...@mail.com wrote:
 Peter Lind wrote:

 On 23 September 2010 21:47, YAD(YetAnotherDavid) ani...@mail.com wrote:

 This code is 95% cut and paste from the PHP manual examples -
 the Types/Strings/Heredocs section and the Filesystem/fnmatch pages.
 There are actually two questions here - I have combined the code into one

  ...

 Question 1 : how to get the newline functioning ? even print_r()
 output
 is not 'newlined' as it should be. Also note the \n is missing between
 the 
  in the output text of the second test!


 Are you outputting to browser or to command line? Browsers have a
 habit of ignoring whitespaces, reducing them to one whitespace
 character regardless of their type or how many.

 Regards
 Peter


 Thanks Peter, - output is to browser, I develop in Notepad++ and Firefox,
 and confirm in IE8. But this stuff used to work - I have been working with
 PHP for about two years (not pro) and am used to formatting my output for
 legibility - especially echoing or var_dumping variables when still testing
 the code. So the failure is recent and I just can't figure what changed.
 David

Browsers treat newlines as any other whitespace - so print_r and
var_dump will not, on their own, provide you with a linebreak in a
browser. If you've got xdebug installed, var_dump will provide a nicer
output (including line-breaks).
However, by far the easiest way to check if you're actually getting
linebreaks in your output is checking the source.

If you're suddenly experiencing a change in output, then some of your
environment variables have changed - hard to say which one without
knowing more about your system, but you must obviously have
changed/updated something for this to happen.

Regards
Peter

-- 
hype
WWW: http://plphp.dk / http://plind.dk
LinkedIn: http://www.linkedin.com/in/plind
BeWelcome/Couchsurfing: Fake51
Twitter: http://twitter.com/kafe15
/hype

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



Re: [PHP] Re: Copying an Object

2010-09-25 Thread Peter Lind
On 25 September 2010 00:11, Daniel Kolbo dko...@gmail.com wrote:
 On 9/24/2010 8:35 AM, Peter Lind wrote:
 On 24 September 2010 14:22, Bob McConnell r...@cbord.com wrote:
 From: David Hutto

 On Fri, Sep 24, 2010 at 4:09 AM, Gary php-gene...@garydjones.name wrote:
 Daniel Kolbo wrote:

 Say you have two classes: human and male.  Further, say male extends
 human.  Let's say you have a human object.  Then later you want to make
 that human object a male object.  This seems to be a pretty reasonable
 thing to request of our objects.

 I don't think any human can change gender without major surgery, but I
 don't know if you just chose your example badly or whether you really
 think objects should be able to mutate into other types of object
 without some kind of special treatment.

 But it would work in something like makehuman, where you start with a 
 neuter
 form and scale one way or the other for physical features. If I
 remember correctly,
 we're' all xx until you become xy(genetically speaking).

 This is one of the details that really bothers me about OOP. It makes it 
 impossible to implement some very reasonable scenarios. 80% of the time, 
 when a patron is added to a system, we don't know which gender they are. 
 More than 50% of the time, we will never know, since the client doesn't 
 keep track of it. But the rest of them will be assigned sometime after they 
 were added. i.e. the gender assignment comes from a secondary source that 
 is not available at the time the patron is entered.


 If you can't handle that, it's not the fault of OOP but your lack of
 programming skills in OOP I'd say (and I mean no disrespect there, I'm
 just pretty sure your scenario can be handled very easily in OOP).

 And no, I have no urge to defend OOP in PHP, I just see this entire
 thread as a complete non-starter: if the language doesn't let you do
 something in a particular way, how about you stop, take a breather,
 then ask if perhaps there's a better way in the language to do what
 you want done? That would normally be a much more productive and
 intelligent response than either a) pressing on in the face of failure
 or b) complaining about your specific needs and how the language fails
 to meet them.

 Regards
 Peter


 I would consider the post to be a discussion among the community to
 discuss possible improvements for php, to help progress the language to
 handle the situations faced by the users of the language, and hey maybe
 learn something along the way.  I certainly wouldn't consider the post
 to be an avenue to belittle members of the community.  For some it's
 half empty, for others half full.
 `

I apologize for the wording of my post - I did not intend to belittle anyone.

Your posts seem to me, however, rather typical: I am coming up
against this problem, why doesn't the language let me solve it the way
I want it to? - something this last response also suggests (I would
consider the post to be a discussion among the community to discuss
possible improvements for php). Many people have already pointed out
that there's likely a much better solution to the problem at hand, yet
you still insist that the language should be improved (the latest idea
being a __cast() function) - and I cannot see you once commenting on
the composition strategy. Was the ... and hey maybe learn something
along the way. meant only for others?

Anyway, seeing as my glass is half-empty and I'm not adding anything
constructive to thread I'll refrain from posting more.

Regards
Peter
-- 
hype
WWW: http://plphp.dk / http://plind.dk
LinkedIn: http://www.linkedin.com/in/plind
BeWelcome/Couchsurfing: Fake51
Twitter: http://twitter.com/kafe15
/hype

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



Re: [PHP] Heredocs, print_r() and newline \n and fnmatch() - curious failures ...

2010-09-24 Thread Peter Lind
On 23 September 2010 21:47, YAD(YetAnotherDavid) ani...@mail.com wrote:
 This code is 95% cut and paste from the PHP manual examples -
 the Types/Strings/Heredocs section and the Filesystem/fnmatch pages.
 There are actually two questions here - I have combined the code into one
 test file ... the strings in the code contain the questions ..
 at the end I have inserted the output I get from the code - identical in
 Firefox and IE8 (so it's not browser related), and on my desktop as well as
 my laptop (so it's not a machine quirk). The setup is Xammplite Win32-1.7.1
 with PHP 5.2.9 and Apache 2.2.11 on both WinXP-SP3 installs.

 I tried Xammp Win32-1.7.3 with the same results. Then I tried installing
 Apache and PHP and MySQL individually, and got the same ...
 Aside from the issue here, I also was unable to get imagick and xdebug
 running on the same installation - it was one or the other. imagick's
 readfile() caused Apache to baulk on PHP5.3.3, so I returned to a fresh
 Xammplite setup. Same results.

 I have spent many hours with this - I would appreciate some insight ..

 Question 1 : how to get the newline functioning ? even print_r() output
 is not 'newlined' as it should be. Also note the \n is missing between the 
  in the output text of the second test!


Are you outputting to browser or to command line? Browsers have a
habit of ignoring whitespaces, reducing them to one whitespace
character regardless of their type or how many.

Regards
Peter

-- 
hype
WWW: http://plphp.dk / http://plind.dk
LinkedIn: http://www.linkedin.com/in/plind
BeWelcome/Couchsurfing: Fake51
Twitter: http://twitter.com/kafe15
/hype

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



Re: [PHP] Re: Copying an Object

2010-09-24 Thread Peter Lind
On 24 September 2010 14:22, Bob McConnell r...@cbord.com wrote:
 From: David Hutto

 On Fri, Sep 24, 2010 at 4:09 AM, Gary php-gene...@garydjones.name wrote:
 Daniel Kolbo wrote:

 Say you have two classes: human and male.  Further, say male extends
 human.  Let's say you have a human object.  Then later you want to make
 that human object a male object.  This seems to be a pretty reasonable
 thing to request of our objects.

 I don't think any human can change gender without major surgery, but I
 don't know if you just chose your example badly or whether you really
 think objects should be able to mutate into other types of object
 without some kind of special treatment.

 But it would work in something like makehuman, where you start with a neuter
 form and scale one way or the other for physical features. If I
 remember correctly,
 we're' all xx until you become xy(genetically speaking).

 This is one of the details that really bothers me about OOP. It makes it 
 impossible to implement some very reasonable scenarios. 80% of the time, when 
 a patron is added to a system, we don't know which gender they are. More than 
 50% of the time, we will never know, since the client doesn't keep track of 
 it. But the rest of them will be assigned sometime after they were added. 
 i.e. the gender assignment comes from a secondary source that is not 
 available at the time the patron is entered.


If you can't handle that, it's not the fault of OOP but your lack of
programming skills in OOP I'd say (and I mean no disrespect there, I'm
just pretty sure your scenario can be handled very easily in OOP).

And no, I have no urge to defend OOP in PHP, I just see this entire
thread as a complete non-starter: if the language doesn't let you do
something in a particular way, how about you stop, take a breather,
then ask if perhaps there's a better way in the language to do what
you want done? That would normally be a much more productive and
intelligent response than either a) pressing on in the face of failure
or b) complaining about your specific needs and how the language fails
to meet them.

Regards
Peter

-- 
hype
WWW: http://plphp.dk / http://plind.dk
LinkedIn: http://www.linkedin.com/in/plind
BeWelcome/Couchsurfing: Fake51
Twitter: http://twitter.com/kafe15
/hype

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



Re: [PHP] Copying an Object

2010-09-23 Thread Peter Lind
On 23 September 2010 02:14, Daniel Kolbo kolb0...@umn.edu wrote:

*snip*

 On 9/22/2010 9:11 AM, chris h wrote:
 Say you have two classes: human and male.  Further, say male extends
 human.  Let's say you have a human object.  Then later you want to make
 that human object a male object.  This seems to be a pretty reasonable
 thing to request of our objects.

Perhaps if you're a C# programmer, but the PHP way of thinking is
radically different.
C#: This object is whatever it was currently cast to (if possible)
PHP: This object is this object, whatever it was created as

If you have a need to make an object switch class in PHP, then there's
a 99% chance you're working against, not with the language.

  This type of thing would especially be
 easy if objects of parent classes could be cast as an object of its
 extended class.

I'll hazard a guess and say you didn't start programming in PHP but in
something else.

Regards
Peter

-- 
hype
WWW: http://plphp.dk / http://plind.dk
LinkedIn: http://www.linkedin.com/in/plind
BeWelcome/Couchsurfing: Fake51
Twitter: http://twitter.com/kafe15
/hype

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



Re: [PHP] Database Administration

2010-09-21 Thread Peter Lind
On 21 September 2010 11:48, Tom Barrett t...@miramedia.co.uk wrote:
 Hi

 I need to build a custom client management app, which will build and manage
 a database per client. This means that on top of the usual sql crud, it
 needs to be able to create databases, add/edit/delete database users, create
 tables.

 Is there a way for me to do this nicely as PHP solution? am I better off
 incorporating non PHP pieces into this (e.g. shell)? or should I leave the
 admin tasks (e.g. database creation) as a 'normal' administrative task
 (commandline/webmin/watever)?


Seeing as all the extra stuff you need is just plain sql commands, I
don't see the problem as such. You just need to make sure access to
the tool is done right (i.e. a user that can create/destroy databases
needs to be aware of this and you need to restrict the access to those
specific persons).

Regards
Peter

-- 
hype
WWW: http://plphp.dk / http://plind.dk
LinkedIn: http://www.linkedin.com/in/plind
BeWelcome/Couchsurfing: Fake51
Twitter: http://twitter.com/kafe15
/hype

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



Re: [PHP] Auto-generating HTML

2010-09-20 Thread Peter Lind
On 20 September 2010 21:56, Andy McKenzie amckenz...@gmail.com wrote:
 On Mon, Sep 20, 2010 at 3:50 PM, Rick Pasotto r...@niof.net wrote:
 On Mon, Sep 20, 2010 at 03:02:35PM -0400, TR Shaw wrote:

 On Sep 20, 2010, at 2:56 PM, Andy McKenzie wrote:

  Hey folks,
 
   I have the feeling this is a stupid question, but I can't even find
  anything about it.  Maybe I'm just not searching for the right things.
 
   Here's the problem.  I'm writing a lot of pages, and I hate going in
  and out of PHP.  At the same time, I want my HTML to be legible.  When
  you look at it, that's kind of a problem, though... for instance
  (assume this had some PHP in the middle, and there was actually a
  reason not to just put this in HTML in the first place):
 
  Simple PHP:
  ?php
 
  echo 'html';
  echo 'head';
  echo '  titlePage Title/title';
  echo '/head';
  echo 'body';
  echo 'pThis is the page body/p';
  echo '/body';
  echo '/html';
 
  ?
 
 
  Output page source:
  htmlhead  titlePage Title/title/headbodypThis is the
  page body/p/body/html
 
 
  Now, I can go through and add a newline to the end of each line (echo
  'html' . \n; and so on), but it adds a lot of typing.  Is there a
  way to make this happen automatically?  I thought about just building
  a simple function, but I run into problem with quotes -- either I
  can't use single quotes, or I can't use double quotes.  Historically,
  I've dealt with the issue by just having ugly output code, but I'd
  like to stop doing that.  How do other people deal with this?
 
  Thanks,
   Alex

 Alex

 Just add a \n at the end as

 echo 'html\n';

 That will not work. Single quotes means that the '\n' is not interpreted
 as a new line so you'll see a bunch of '\n' in the output.

 What I sometimes do is:

 $out = array();
 $out[] = 'html';
 $out[] = 'head';
 $out[] = '  titlePage Title/title';
 $out[] = '/head';
 $out[] = 'body';
 $out[] = 'pThis is the page body/p';
 $out[] = '/body';
 $out[] = '/html';
 echo join(\n,$out);


 Interesting.  I hadn't thought of that, but it could work.  It'd still
 be quite a bit of extra typing, but at least I find it more
 readable...


Ash already mentioned it: heredoc format. Much easier, less typing,
easier to read, keeps formatting, etc, etc etc.

Regards
Peter

-- 
hype
WWW: http://plphp.dk / http://plind.dk
LinkedIn: http://www.linkedin.com/in/plind
BeWelcome/Couchsurfing: Fake51
Twitter: http://twitter.com/kafe15
/hype

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



Re: [PHP] GD Watermark Question

2010-09-19 Thread Peter Lind
On 19 September 2010 16:05, tedd tedd.sperl...@gmail.com wrote:
 At 6:03 PM -0400 9/17/10, Gary wrote:

 Is there a way to insert a watermark on an image as it is being uploaded
 to
 the image file, then removed when it is called from a database to be
 viewed
 on a website?

 The rational behind this is I have a photographers site I am doing, and I
 am
 limiting the size of the images somewhat to reduce pilferage and I would
 like to be able to show the images a little larger, hence with a bit more
 clarity and detail.

 Thanks for your input.

 Gary

 Gary:

 Don't complicate this process more than necessary.

 Simply upload the image file normally and store it in the file system OR the
 database.

 When you want to show the image as a thumbnail, then show it. Here's the
 code:

 http://webbytedd.com/b/thumb/

 If you want to show it with a watermark, then show that. Again, here's the
 code:

 http://webbytedd.com/b/watermark/

 If you want to show the image as a thumbnail with a watermark, then combine
 the two routines. I'll leave that to you.


You're generating the thumbnail on every request. Just generate it
once and serve the thumbnail as a file (there's no reason why you
would need to invoke php to show a thumbnail of an image).
Regards
Peter

-- 
hype
WWW: http://plphp.dk / http://plind.dk
LinkedIn: http://www.linkedin.com/in/plind
BeWelcome/Couchsurfing: Fake51
Twitter: http://twitter.com/kafe15
/hype

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



Re: [PHP] Session Vars loaded from MSSQL Query drop, those loaded from MYSQL Query stick

2010-09-16 Thread Peter Lind
On 16 September 2010 16:26, Cheryl Sullivan csull...@shh.org wrote:
 Absolutely -



 This is from the first page



 ?php

 $_SESSION['UserLastName'] = strtolower(trim($_POST['txtLastName']));

 $_SESSION['BadgeID'] = trim($_POST['txtBadgeID']);



 //access MS SQL Server database

 $q1 = select * from emps where emp_last =
 '.$_SESSION['UserLastName'].' and emp_badge =
 '.$_SESSION['BadgeID'].';

 $rs_emp_info = hitMSSQL($q1,_sql,database,table,password,1);

 $_SESSION['SSN'] = $rs_emp_info-fields(emp_ssn);

 $_SESSION['CostCenter'] = $rs_emp_info-fields(emp_costcenter);


You're sticking values from $_POST into an SQL query without
sanitizing them first. That spells out SQL INJECTION VULNERABILITY.

Regards
Peter

-- 
hype
WWW: http://plphp.dk / http://plind.dk
LinkedIn: http://www.linkedin.com/in/plind
BeWelcome/Couchsurfing: Fake51
Twitter: http://twitter.com/kafe15
/hype

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



  1   2   3   4   >