php-general Digest 2 Jul 2012 11:59:05 -0000 Issue 7874

2012-07-02 Thread php-general-digest-help

php-general Digest 2 Jul 2012 11:59:05 - Issue 7874

Topics (messages 318359 through 318361):

Re: Hello again
318359 by: tamouse mailing lists

Re: php form action breaks script
318360 by: Ford, Mike

Destructor not called when extending SimpleXMLElement
318361 by: Nick Chalk

Administrivia:

To subscribe to the digest, e-mail:
php-general-digest-subscr...@lists.php.net

To unsubscribe from the digest, e-mail:
php-general-digest-unsubscr...@lists.php.net

To post to the list, e-mail:
php-gene...@lists.php.net


--
---BeginMessage---
On Sun, Jul 1, 2012 at 6:21 PM, RGraph.net support supp...@rgraph.net wrote:
 Just thought I'd say hello again. Back to brush up on my PHP a little
 after a bit of a break - more reading than replying I'd imagine. I
 have some pretty bad jokes too that I might surreptitiously insert
 here and there...

Welcome back. Friday is mainly the free-for-all day (philosophical
questions, puns, jokes)
---End Message---
---BeginMessage---
 -Original Message-
 From: Tim Dunphy [mailto:bluethu...@gmail.com]
 Sent: 28 June 2012 01:18
 
 Hey guys,
 
 It's been a little while since I've toyed with this, and I hope you
 don't mind my coming back to you for some more advice. But I've
 enjoyed some limited success with David R's advice regarding adding
 some strong quoting to the mix. Here is what I last tried -
 
  form method=post action=' . $_SERVER['[PHP_SELF'] .'

Wow! That's completely wacko! (OK, just looked at the full code and
seen it's in the middle of a single-quoted echo, so it's not that bad
after all :). You've got a spare [ in there -- the notice saying
Undefined index: [PHP_SELF should have alerted you to this, as the
index you want is just plain PHP_SELF.

   form method=post action=' . $_SERVER['PHP_SELF'] .'

 The pages do work, and the form checking code does its job (empty
 text
 displays what information is missing). Except that there is an
 annoying message that appears on screen and in the logs -
 
 Notice: Undefined index: subject in
 /Library/WebServer/Documents/examples/ch03/final/makemeelvis/sendema
 il.php
 on line 23 Notice: Undefined index: elvismail in
 /Library/WebServer/Documents/examples/ch03/final/makemeelvis/sendema
 il.php
 on line 24 Notice: Undefined index: [PHP_SELF in
 /Library/WebServer/Documents/examples/ch03/final/makemeelvis/sendema
 il.php
 on line 62

Looking at the relevant bit of your script (assume this is line 23
onward):

   $subject = $_POST['subject'];
   $text = $_POST['elvismail'];
   $output_form = false;
 
 
   if (isset($_POST['Submit'])) {

You're accessing $_POST['subject'] and $_POST['elvismail'] *before* the
check to see if this is a from a form submission - on the initial access,
to just display the form, these $_POST indexes will not be set so
causing the notices.

You either need to put the assignments inside the

  if (isset($POST['Submit']))

branch, or conditionalise them in some way, such as:

$subject = isset($_POST['subject']) ? $_POST['subject'] : NULL;
$text = isset($_POST['elvismail']) ? $_POST['elvismail'] : NULL;


Another oddity in your script is that you're using the string values
true and false instead of the Boolean true and false. Because of
the way PHP typecasts, both true and false are actually regarded
as Boolean true, which could get a little confusing -- so it's much
better (and probably more efficient) to use the proper Boolean values.
Also, it enables your later test to be written, with confidence, as
just

if ($output_form) {


Also, also, with a little bit of rearrangement of the tests, you can
reduce the amount of code a bit:

if (!empty($subject)  !empty($text)) {
// Both inputs supplied -- good to go.
$output_form = false;
} else {
// At least one input missing -- need to redisplay form
$output_form = true;

if (empty($subject)) {
if (empty($text)) {
echo 'You forgot the email subject and body.br /';
} else {
echo 'You forgot the email subject.br /';
}
} else {
echo 'You forgot the email body text.br /';
}
}

Actually, I think my inclination would be to assign $output_form
first, and then do the rest of the tests:

$output_form = empty($subject) || empty($text);

if ($output_form) {
// At least one input missing -- work out which one
if (empty($subject))
if (empty($text)) {
echo 'You forgot the email subject and body.br /';
} else {
echo 'You forgot the email subject.br /';
}
} else {
echo 'You forgot the email body text.br /';
}
}

That said, there are lots of personal preferences involved here, and
I'm sure others would offer different possibilities. (Me personally,
I also prefer the 

php-general Digest 3 Jul 2012 02:15:19 -0000 Issue 7875

2012-07-02 Thread php-general-digest-help

php-general Digest 3 Jul 2012 02:15:19 - Issue 7875

Topics (messages 318362 through 318381):

Re: Destructor not called when extending SimpleXMLElement
318362 by: Erwin Poeze
318368 by: Matijn Woudt

Re: log tailing
318363 by: Mihamina Rakotomandimby
318366 by: Matijn Woudt

Re: embedding php inside of php
318364 by: Daniel Brown
318367 by: Matijn Woudt

PHP/mySQL Developer Partner needed...
318365 by: Don Wieland

Way to test if variable contains valid date
318369 by: Ron Piggott
318370 by: Daniel Brown
318371 by: Ron Piggott

PHP Time
318372 by: Rob Weissenburger
318373 by: Daniel Brown
318374 by: Geoff Shang
318375 by: Rob Weissenburger

PDO Prevent duplicate field names?
318376 by: Scott Baker
318377 by: Matijn Woudt
318378 by: Scott Baker
318379 by: Matijn Woudt
318380 by: Jim Lucas

How does this code work?
318381 by: Robert Williams

Administrivia:

To subscribe to the digest, e-mail:
php-general-digest-subscr...@lists.php.net

To unsubscribe from the digest, e-mail:
php-general-digest-unsubscr...@lists.php.net

To post to the list, e-mail:
php-gene...@lists.php.net


--
---BeginMessage---
Interesting problem. I would expect it to work too. I assume it is a bug.


2012/7/2 Nick Chalk n...@loadbalancer.org

 Afternoon all.

 I seem to be having a little trouble with extending the
 SimpleXMLElement class. I would like to add a destructor to the
 subclass, but am finding that it is not called.

 Attached is a minimal demonstration of the problem. The XMLConfig
 class extends SimpleXMLElement, and its destructor is not called. The
 XMLConfig2 class, which does not use inheritance, does have its
 destructor called.

 The test platform is CentOS 6.2, with PHP version 5.3.3.

 What am I missing?

 Thanks for your help.
 Nick.

 --
 Nick Chalk.

 Loadbalancer.org Ltd.
 Phone: +44 (0)870 443 8779
 http://www.loadbalancer.org/

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

---End Message---
---BeginMessage---
On Mon, Jul 2, 2012 at 1:58 PM, Nick Chalk n...@loadbalancer.org wrote:
 Afternoon all.

 I seem to be having a little trouble with extending the
 SimpleXMLElement class. I would like to add a destructor to the
 subclass, but am finding that it is not called.

 Attached is a minimal demonstration of the problem. The XMLConfig
 class extends SimpleXMLElement, and its destructor is not called. The
 XMLConfig2 class, which does not use inheritance, does have its
 destructor called.

 The test platform is CentOS 6.2, with PHP version 5.3.3.

 What am I missing?

 Thanks for your help.
 Nick.


Hi Nick,

This is most likely a bug in PHP. A deconstructor is called when there
are no references left to the object. Since this class uses the libXML
library, it is likely that there are still references from the libXML
open on the object, which is why it will never be destroyed.
Anyway, you should report this bug to the PHP devs (at bugs.php.net).

If you really need this, it's probably best to create a class that
does not really extend SimpleXMLElement, but you create one inside the
constructor, and just forward all function calls to the
SimpleXMLElement object you've created in the constructor.

- Matijn
---End Message---
---BeginMessage---

On 06/30/2012 09:32 PM, Daniel Brown wrote:

?php
$ssh_entries = explode(PHP_EOL,trim(`tail /var/log/syslog | awk
{'print $1,$2,$3 | $5 | $11'}`));


This will tail a default number of lines.

I'm looking for a way to identify the last line, and when launching the 
PHP script I get the added line between now and that last one.


There is a logtail utility in the logtool package, but I want a full 
PHP equivalent.


The logtail utility inserts a marker in the logfile, which I find 
intrusive and requiring root privilege.


My guess is identifying lines with hash or storing the last line in e 
tmp file, or...


I'm looking for the least worst solution.

--
RMA.


---End Message---
---BeginMessage---
On Mon, Jul 2, 2012 at 3:23 PM, Mihamina Rakotomandimby
miham...@rktmb.org wrote:
 On 06/30/2012 09:32 PM, Daniel Brown wrote:

 ?php
 $ssh_entries = explode(PHP_EOL,trim(`tail /var/log/syslog | awk
 {'print $1,$2,$3 | $5 | $11'}`));


 This will tail a default number of lines.

 I'm looking for a way to identify the last line, and when launching the PHP
 script I get the added line between now and that last one.

 There is a logtail utility in the logtool package, but I want a full PHP
 equivalent.

 The logtail utility inserts a marker in the logfile, which I find
 intrusive and requiring root privilege.

 My guess is identifying lines with hash or storing the last line in e tmp
 file, or...

 I'm looking for the least worst solution.

 --
 RMA.

You could also 

Re: [PHP] Hello again

2012-07-02 Thread tamouse mailing lists
On Sun, Jul 1, 2012 at 6:21 PM, RGraph.net support supp...@rgraph.net wrote:
 Just thought I'd say hello again. Back to brush up on my PHP a little
 after a bit of a break - more reading than replying I'd imagine. I
 have some pretty bad jokes too that I might surreptitiously insert
 here and there...

Welcome back. Friday is mainly the free-for-all day (philosophical
questions, puns, jokes)

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



RE: [PHP] Re: php form action breaks script

2012-07-02 Thread Ford, Mike
 -Original Message-
 From: Tim Dunphy [mailto:bluethu...@gmail.com]
 Sent: 28 June 2012 01:18
 
 Hey guys,
 
 It's been a little while since I've toyed with this, and I hope you
 don't mind my coming back to you for some more advice. But I've
 enjoyed some limited success with David R's advice regarding adding
 some strong quoting to the mix. Here is what I last tried -
 
  form method=post action=' . $_SERVER['[PHP_SELF'] .'

Wow! That's completely wacko! (OK, just looked at the full code and
seen it's in the middle of a single-quoted echo, so it's not that bad
after all :). You've got a spare [ in there -- the notice saying
Undefined index: [PHP_SELF should have alerted you to this, as the
index you want is just plain PHP_SELF.

   form method=post action=' . $_SERVER['PHP_SELF'] .'

 The pages do work, and the form checking code does its job (empty
 text
 displays what information is missing). Except that there is an
 annoying message that appears on screen and in the logs -
 
 Notice: Undefined index: subject in
 /Library/WebServer/Documents/examples/ch03/final/makemeelvis/sendema
 il.php
 on line 23 Notice: Undefined index: elvismail in
 /Library/WebServer/Documents/examples/ch03/final/makemeelvis/sendema
 il.php
 on line 24 Notice: Undefined index: [PHP_SELF in
 /Library/WebServer/Documents/examples/ch03/final/makemeelvis/sendema
 il.php
 on line 62

Looking at the relevant bit of your script (assume this is line 23
onward):

   $subject = $_POST['subject'];
   $text = $_POST['elvismail'];
   $output_form = false;
 
 
   if (isset($_POST['Submit'])) {

You're accessing $_POST['subject'] and $_POST['elvismail'] *before* the
check to see if this is a from a form submission - on the initial access,
to just display the form, these $_POST indexes will not be set so
causing the notices.

You either need to put the assignments inside the

  if (isset($POST['Submit']))

branch, or conditionalise them in some way, such as:

$subject = isset($_POST['subject']) ? $_POST['subject'] : NULL;
$text = isset($_POST['elvismail']) ? $_POST['elvismail'] : NULL;


Another oddity in your script is that you're using the string values
true and false instead of the Boolean true and false. Because of
the way PHP typecasts, both true and false are actually regarded
as Boolean true, which could get a little confusing -- so it's much
better (and probably more efficient) to use the proper Boolean values.
Also, it enables your later test to be written, with confidence, as
just

if ($output_form) {


Also, also, with a little bit of rearrangement of the tests, you can
reduce the amount of code a bit:

if (!empty($subject)  !empty($text)) {
// Both inputs supplied -- good to go.
$output_form = false;
} else {
// At least one input missing -- need to redisplay form
$output_form = true;

if (empty($subject)) {
if (empty($text)) {
echo 'You forgot the email subject and body.br /';
} else {
echo 'You forgot the email subject.br /';
}
} else {
echo 'You forgot the email body text.br /';
}
}

Actually, I think my inclination would be to assign $output_form
first, and then do the rest of the tests:

$output_form = empty($subject) || empty($text);

if ($output_form) {
// At least one input missing -- work out which one
if (empty($subject))
if (empty($text)) {
echo 'You forgot the email subject and body.br /';
} else {
echo 'You forgot the email subject.br /';
}
} else {
echo 'You forgot the email body text.br /';
}
}

That said, there are lots of personal preferences involved here, and
I'm sure others would offer different possibilities. (Me personally,
I also prefer the alternative block syntax with initial : and end...
tags -- but then, the forests of curly braces others seem to find
acceptable make my eyes go fuzzy, so go figure)

Cheers!

Mike

-- 
Mike Ford,
Electronic Information Developer, Libraries and Learning Innovation,  
Portland PD507, City Campus, Leeds Metropolitan University,
Portland Way, LEEDS,  LS1 3HE,  United Kingdom 
E: m.f...@leedsmet.ac.uk T: +44 113 812 4730






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

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



[PHP] Destructor not called when extending SimpleXMLElement

2012-07-02 Thread Nick Chalk
Afternoon all.

I seem to be having a little trouble with extending the
SimpleXMLElement class. I would like to add a destructor to the
subclass, but am finding that it is not called.

Attached is a minimal demonstration of the problem. The XMLConfig
class extends SimpleXMLElement, and its destructor is not called. The
XMLConfig2 class, which does not use inheritance, does have its
destructor called.

The test platform is CentOS 6.2, with PHP version 5.3.3.

What am I missing?

Thanks for your help.
Nick.

-- 
Nick Chalk.

Loadbalancer.org Ltd.
Phone: +44 (0)870 443 8779
http://www.loadbalancer.org/
attachment: minimal_test.php
-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: [PHP] Destructor not called when extending SimpleXMLElement

2012-07-02 Thread Erwin Poeze
Interesting problem. I would expect it to work too. I assume it is a bug.


2012/7/2 Nick Chalk n...@loadbalancer.org

 Afternoon all.

 I seem to be having a little trouble with extending the
 SimpleXMLElement class. I would like to add a destructor to the
 subclass, but am finding that it is not called.

 Attached is a minimal demonstration of the problem. The XMLConfig
 class extends SimpleXMLElement, and its destructor is not called. The
 XMLConfig2 class, which does not use inheritance, does have its
 destructor called.

 The test platform is CentOS 6.2, with PHP version 5.3.3.

 What am I missing?

 Thanks for your help.
 Nick.

 --
 Nick Chalk.

 Loadbalancer.org Ltd.
 Phone: +44 (0)870 443 8779
 http://www.loadbalancer.org/

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



Re: [PHP] log tailing

2012-07-02 Thread Mihamina Rakotomandimby

On 06/30/2012 09:32 PM, Daniel Brown wrote:

?php
$ssh_entries = explode(PHP_EOL,trim(`tail /var/log/syslog | awk
{'print $1,$2,$3 | $5 | $11'}`));


This will tail a default number of lines.

I'm looking for a way to identify the last line, and when launching the 
PHP script I get the added line between now and that last one.


There is a logtail utility in the logtool package, but I want a full 
PHP equivalent.


The logtail utility inserts a marker in the logfile, which I find 
intrusive and requiring root privilege.


My guess is identifying lines with hash or storing the last line in e 
tmp file, or...


I'm looking for the least worst solution.

--
RMA.



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



Re: [PHP] embedding php inside of php

2012-07-02 Thread Daniel Brown
On Sat, Jun 30, 2012 at 8:00 PM, Tim Dunphy bluethu...@gmail.com wrote:
 Hello,

  I am trying to get the hang of php using some examples that I found
 in a book. I've been making progress lately, but one thing has me a
 bit stumped.


 In an HTML form that I am echoing through PHP I would like to embed
 smaller chunks of php in the code like so:


  echo 'br /br /
 form method=post action=sendemail.php
 label for=subjectSubject of email:/labelbr /
 input id=subject name=subject type=text value=?php
 echo $subject;?br /

You're trying to open PHP tags within a PHP code block.  Drop the
nested ?php echo $subject; ? and replace it with:

'.$subject.'

Thus:

echo 'br/br/
form method=post action=sendmail.php
label for=subjectSubject of email /labelbr/
input id=subject name=subject type=text
value='.$subject.'br/

-- 
/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



[PHP] PHP/mySQL Developer Partner needed...

2012-07-02 Thread Don Wieland

Greetings,

I have a site that I am developing and I am looking to partner/ 
developer with great php/mySQL skills (for share of potential profits)  
to assist me in finishing this site. I am looking for someone who can  
invest (like myself) their time and skills to complete the site in  
exchange for a percentage of profits the site will make. This is a  
side project for me, so I am looking for someone who would like to  
invest 8-10 hours a week to finish this site. To reiterate, I am  
looking for partner to invest their time and skills. I am not looking  
to pay someone an hourly wage for the work they do on the site ;-)


If you are interested, please contact me PRIVATELY and include a few  
examples of your work (websites,etc...). Thanks.


Don

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



Re: [PHP] log tailing

2012-07-02 Thread Matijn Woudt
On Mon, Jul 2, 2012 at 3:23 PM, Mihamina Rakotomandimby
miham...@rktmb.org wrote:
 On 06/30/2012 09:32 PM, Daniel Brown wrote:

 ?php
 $ssh_entries = explode(PHP_EOL,trim(`tail /var/log/syslog | awk
 {'print $1,$2,$3 | $5 | $11'}`));


 This will tail a default number of lines.

 I'm looking for a way to identify the last line, and when launching the PHP
 script I get the added line between now and that last one.

 There is a logtail utility in the logtool package, but I want a full PHP
 equivalent.

 The logtail utility inserts a marker in the logfile, which I find
 intrusive and requiring root privilege.

 My guess is identifying lines with hash or storing the last line in e tmp
 file, or...

 I'm looking for the least worst solution.

 --
 RMA.

You could also remember the number of bytes read, store that (in a tmp
file or database), and use fseek() to skip to that exact position.

- Matijn

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



Re: [PHP] embedding php inside of php

2012-07-02 Thread Matijn Woudt
Hi,

rant
First a message to the ones that have responded before me:
You're correct about the nested php tags that are not doing what the
OP wanted, but you might want to take a closer look at the error
that's in the logs. In ANY CASE PHP SHOULD NOT CRASH. What if the OP
really wanted to print PHP tags inside it's textbox? That's perfectly
valid. I tested the code, and it works fine on my machine, even though
I get PHP tags inside the output.
/rant

On Sun, Jul 1, 2012 at 2:00 AM, Tim Dunphy bluethu...@gmail.com wrote:
 Hello,

  I am trying to get the hang of php using some examples that I found
 in a book. I've been making progress lately, but one thing has me a
 bit stumped.


 In an HTML form that I am echoing through PHP I would like to embed
 smaller chunks of php in the code like so:


  echo 'br /br /
 form method=post action=sendemail.php
 label for=subjectSubject of email:/labelbr /
 input id=subject name=subject type=text value=?php
 echo $subject;?br /
 label for=elvismailBody of email:/labelbr /
 textarea id=elvismail name=elvismail rows=8
 cols=40?php echo $text;?   /textareabr /
 input type=submit name=Submit value=Submit /
 /form';



 If I do embed the smaller chunks of php in the form the way I've just
 shown you the script instantly breaks and the web page shows only a
 white screen of death.

 And I see this in the web server logs

 [Sat Jun 30 19:12:54 2012] [notice] child pid 7769 exit signal
 Segmentation fault (11)


What version of Operating System, Webserver(Apache?) and PHP are you
using? It seems like there is a bug in your PHP, so if you're not yet
at the latest version, you might want to upgrade your Webserver/PHP.

- Matijn

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



Re: [PHP] Destructor not called when extending SimpleXMLElement

2012-07-02 Thread Matijn Woudt
On Mon, Jul 2, 2012 at 1:58 PM, Nick Chalk n...@loadbalancer.org wrote:
 Afternoon all.

 I seem to be having a little trouble with extending the
 SimpleXMLElement class. I would like to add a destructor to the
 subclass, but am finding that it is not called.

 Attached is a minimal demonstration of the problem. The XMLConfig
 class extends SimpleXMLElement, and its destructor is not called. The
 XMLConfig2 class, which does not use inheritance, does have its
 destructor called.

 The test platform is CentOS 6.2, with PHP version 5.3.3.

 What am I missing?

 Thanks for your help.
 Nick.


Hi Nick,

This is most likely a bug in PHP. A deconstructor is called when there
are no references left to the object. Since this class uses the libXML
library, it is likely that there are still references from the libXML
open on the object, which is why it will never be destroyed.
Anyway, you should report this bug to the PHP devs (at bugs.php.net).

If you really need this, it's probably best to create a class that
does not really extend SimpleXMLElement, but you create one inside the
constructor, and just forward all function calls to the
SimpleXMLElement object you've created in the constructor.

- Matijn

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



Re: [PHP] Way to test if variable contains valid date

2012-07-02 Thread Daniel Brown
On Mon, Jul 2, 2012 at 2:54 PM, Ron Piggott
ron.pigg...@actsministries.org wrote:

 Is there a way to test a variable contains a valid date
 - 4 digits for the year
 - 2 digits for the month (including leading 0)
 - 2 digits for the day (including leading 0)

 OR

 - a function?

You may want to check out checkdate():

http://php.net/checkdate

-- 
/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: [PHP] Way to test if variable contains valid date

2012-07-02 Thread Ron Piggott

On Mon, Jul 2, 2012 at 2:54 PM, Ron Piggott
ron.pigg...@actsministries.org wrote:


Is there a way to test a variable contains a valid date
- 4 digits for the year
- 2 digits for the month (including leading 0)
- 2 digits for the day (including leading 0)

OR

- a function?


   You may want to check out checkdate():

   http://php.net/checkdate

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


Hi Daniel

I want to thank you, Daniel, for this help.  
- I was looking for an isarray type function


www.TheVerseOfTheDay.info 


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



[PHP] PHP Time

2012-07-02 Thread Rob Weissenburger
Hello everyone,

  I know php time() gives the current unix time which you can format out to
a normal date and time. Is there a way to format a specific date and time
back to unix time?

Thanks for any help.



Re: [PHP] PHP Time

2012-07-02 Thread Daniel Brown
On Mon, Jul 2, 2012 at 4:00 PM, Rob Weissenburger r...@fiberuplink.com wrote:
 Hello everyone,

   I know php time() gives the current unix time which you can format out to
 a normal date and time. Is there a way to format a specific date and time
 back to unix time?

Yup.  Look at strtotime() and mktime():

http://php.net/strtotime
http://php.net/mktime

-- 
/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: [PHP] PHP Time

2012-07-02 Thread Geoff Shang

On Mon, 2 Jul 2012, Rob Weissenburger wrote:


 I know php time() gives the current unix time which you can format out to
a normal date and time. Is there a way to format a specific date and time
back to unix time?


mktime() and strtotime() will do it, depending on the form your time is 
in.  There's probably others.


Geoff.


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



RE: [PHP] PHP Time

2012-07-02 Thread Rob Weissenburger
That worked just perfectly. Thank you.

-Original Message-
From: paras...@gmail.com [mailto:paras...@gmail.com] On Behalf Of Daniel
Brown
Sent: Monday, July 02, 2012 3:02 PM
To: Rob Weissenburger
Cc: php-general@lists.php.net
Subject: Re: [PHP] PHP Time

On Mon, Jul 2, 2012 at 4:00 PM, Rob Weissenburger r...@fiberuplink.com
wrote:
 Hello everyone,

   I know php time() gives the current unix time which you can format 
 out to a normal date and time. Is there a way to format a specific 
 date and time back to unix time?

Yup.  Look at strtotime() and mktime():

http://php.net/strtotime
http://php.net/mktime

--
/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


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



[PHP] PDO Prevent duplicate field names?

2012-07-02 Thread Scott Baker
$sql = SELECT First, Last, Age, 'Foobar' AS Last;;

This is a simplified example of a SQL query where we're returning two
fields with the same name (Last). When I do a fetch_assoc with this
query I only get three fields, as the second Last field over writes
the first one.

I was hoping there was some method with PDO that would detect that and
throw a warning. Maybe some sort of strict mode that would tell me I'm
doing something stupid. Is there a way to catch this before it bites me?

It already bit me, but moving forward it'd be nice if PHP saw that
before I spent an hour debugging it again.

- Scott

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



Re: [PHP] PDO Prevent duplicate field names?

2012-07-02 Thread Matijn Woudt
On Tue, Jul 3, 2012 at 12:25 AM, Scott Baker bak...@canbytel.com wrote:
 $sql = SELECT First, Last, Age, 'Foobar' AS Last;;

 This is a simplified example of a SQL query where we're returning two
 fields with the same name (Last). When I do a fetch_assoc with this
 query I only get three fields, as the second Last field over writes
 the first one.

 I was hoping there was some method with PDO that would detect that and
 throw a warning. Maybe some sort of strict mode that would tell me I'm
 doing something stupid. Is there a way to catch this before it bites me?

 It already bit me, but moving forward it'd be nice if PHP saw that
 before I spent an hour debugging it again.

 - Scott


Why the  would you want to return 2 columns with the same name?
To be short, there's no such function, so you have to:
1) Rename one of the columns
2) or, use fetch_row with numerical indexes instead of fetch_assoc.

- Matijn

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



Re: [PHP] PDO Prevent duplicate field names?

2012-07-02 Thread Scott Baker
On 07/02/2012 03:34 PM, Matijn Woudt wrote:
 Why the  would you want to return 2 columns with the same name?
 To be short, there's no such function, so you have to:
 1) Rename one of the columns
 2) or, use fetch_row with numerical indexes instead of fetch_assoc.

My real world scenario was this

SELECT a.CustID, b.*
FROM Customer a
LEFT JOIN Sales B USING (CustID)
WHERE a.CustID = 1234;

In that case, there was a record in Customer, but not in Sales. Sales
returned CustID as NULL, which overwrote the one from Customer.

It was my mistake, and the SQL was easily fixed. But it woulda been nice
to have PHP realize there was a dupe when it was building that array to
return to me.


-- 
Scott Baker - Canby Telcom
System Administrator - RHCE - 503.266.8253



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



Re: [PHP] PDO Prevent duplicate field names?

2012-07-02 Thread Matijn Woudt
On Tue, Jul 3, 2012 at 12:38 AM, Scott Baker bak...@canbytel.com wrote:
 On 07/02/2012 03:34 PM, Matijn Woudt wrote:
 Why the  would you want to return 2 columns with the same name?
 To be short, there's no such function, so you have to:
 1) Rename one of the columns
 2) or, use fetch_row with numerical indexes instead of fetch_assoc.

 My real world scenario was this

 SELECT a.CustID, b.*
 FROM Customer a
 LEFT JOIN Sales B USING (CustID)
 WHERE a.CustID = 1234;

 In that case, there was a record in Customer, but not in Sales. Sales
 returned CustID as NULL, which overwrote the one from Customer.

 It was my mistake, and the SQL was easily fixed. But it woulda been nice
 to have PHP realize there was a dupe when it was building that array to
 return to me.


Which makes me wonder, why are you returning a.CustID, if b includes
CustID too and a.CustID == b.CustID?

As to why there are no checks,.. I guess it's just that it's not a
common error. And after all, all it does is set a value in an array
twice, that doesn't result in warnings elsewhere (thank god ;))

- Matijn

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



Re: [PHP] PDO Prevent duplicate field names?

2012-07-02 Thread Jim Lucas

On 07/02/2012 03:38 PM, Scott Baker wrote:

On 07/02/2012 03:34 PM, Matijn Woudt wrote:

Why the  would you want to return 2 columns with the same name?
To be short, there's no such function, so you have to:
1) Rename one of the columns
2) or, use fetch_row with numerical indexes instead of fetch_assoc.


My real world scenario was this

SELECT a.CustID, b.*
FROM Customer a
LEFT JOIN Sales B USING (CustID)
WHERE a.CustID = 1234;

In that case, there was a record in Customer, but not in Sales. Sales
returned CustID as NULL, which overwrote the one from Customer.

It was my mistake, and the SQL was easily fixed. But it woulda been nice
to have PHP realize there was a dupe when it was building that array to
return to me.




You could always do this.

SELECT b.*, a.CustID
FROM Customer a
LEFT JOIN Sales B USING (CustID)
WHERE a.CustID = 1234;

--
Jim Lucas

http://www.cmsws.com/
http://www.cmsws.com/examples/
http://www.bendsource.com/

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



[PHP] How does this code work?

2012-07-02 Thread Robert Williams
I found this code in a user comment in the PHP docs for htmlentities():

?php

function xml_character_encode($string, $trans='') {
$trans = (is_array($trans)) ? $trans : 
get_html_translation_table(HTML_ENTITIES, ENT_QUOTES);
foreach ($trans as $k=$v)
$trans[$k]= #.ord($k).;;

return strtr($string, $trans);
}

?

It seems to work. For instance, this (assuming UTF-8 encoding):

echo xml_character_encode('Château');
echo \n;
echo xml_character_encode('Chteau');

Yields this:

Ch#195;#162;teau
Ch#38;teau

My question is, *how* does it work? It makes sense right up to the return 
statement. According to the docs for strstr(), when a non-string is passed in 
as the needle, it's, converted to an integer and applied as the ordinal value 
of a character. First, an array-to-int conversion is undefined, though it 
seems to produce 1 on my copy of PHP. Now, I'm not quite sure how to interpret 
the last part of that statement from the docs, but I take it that the ultimate 
value supplied to strstr() is going to be either '1' (the character value of 
the integer value of the array) or '49' (the ordinal value of the character 
'1'). Whatever, neither one makes sense to look for in the haystack, so I'm 
obviously missing something.

Perhaps it's just late-Monday slowness on my part, but what's going on here? I 
have no intention of using this code, but I'd sure like to understand how it 
works!


Regards,
Bob
--
Robert E. Williams, Jr.
Associate Vice President of Software Development
Newtek Businesss Services, Inc. -- The Small Business Authority
https://www.newtekreferrals.com/rewjr
http://www.thesba.com/


Notice: This communication, including attachments, may contain information that 
is confidential. It constitutes non-public information intended to be conveyed 
only to the designated recipient(s). If the reader or recipient of this 
communication is not the intended recipient, an employee or agent of the 
intended recipient who is responsible for delivering it to the intended 
recipient, or if you believe that you have received this communication in 
error, please notify the sender immediately by return e-mail and promptly 
delete this e-mail, including attachments without reading or saving them in any 
manner. The unauthorized use, dissemination, distribution, or reproduction of 
this e-mail, including attachments, is prohibited and may be unlawful. If you 
have received this email in error, please notify us immediately by e-mail or 
telephone and delete the e-mail and the attachments (if any).


Re: [PHP] How does this code work?

2012-07-02 Thread Jim Lucas

On 7/2/2012 7:15 PM, Robert Williams wrote:

I found this code in a user comment in the PHP docs for htmlentities():

?php

function xml_character_encode($string, $trans='') {
$trans = (is_array($trans)) ? $trans : 
get_html_translation_table(HTML_ENTITIES, ENT_QUOTES);
foreach ($trans as $k=$v)
$trans[$k]= #.ord($k).;;

return strtr($string, $trans);
}

?

It seems to work. For instance, this (assuming UTF-8 encoding):

echo xml_character_encode('Château');
echo \n;
echo xml_character_encode('Chteau');

Yields this:

Ch#195;#162;teau
Ch#38;teau

My question is, *how* does it work? It makes sense right up to the return statement. 
According to the docs for strstr(), when a non-string is passed in as the needle, it's, 
converted to an integer and applied as the ordinal value of a character. 
First, an array-to-int conversion is undefined, though it seems to produce 1 on my copy 
of PHP. Now, I'm not quite sure how to interpret the last part of that statement from the 
docs, but I take it that the ultimate value supplied to strstr() is going to be either 
'1' (the character value of the integer value of the array) or '49' (the ordinal value of 
the character '1'). Whatever, neither one makes sense to look for in the haystack, so I'm 
obviously missing something.


I think you missed something here...

The above function uses strtr() not strstr()

http://php.net/strtr
http://php.net/strstr



Perhaps it's just late-Monday slowness on my part, but what's going on here? I 
have no intention of using this code, but I'd sure like to understand how it 
works!


Regards,
Bob
--
Robert E. Williams, Jr.
Associate Vice President of Software Development
Newtek Businesss Services, Inc. -- The Small Business Authority
https://www.newtekreferrals.com/rewjr
http://www.thesba.com/


Notice: This communication, including attachments, may contain information that 
is confidential. It constitutes non-public information intended to be conveyed 
only to the designated recipient(s). If the reader or recipient of this 
communication is not the intended recipient, an employee or agent of the 
intended recipient who is responsible for delivering it to the intended 
recipient, or if you believe that you have received this communication in 
error, please notify the sender immediately by return e-mail and promptly 
delete this e-mail, including attachments without reading or saving them in any 
manner. The unauthorized use, dissemination, distribution, or reproduction of 
this e-mail, including attachments, is prohibited and may be unlawful. If you 
have received this email in error, please notify us immediately by e-mail or 
telephone and delete the e-mail and the attachments (if any).





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