php-general Digest 3 Jul 2012 02:15:19 -0000 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
----------------------------------------------------------------------
--- Begin Message ---
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 ---
--- Begin Message ---
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 ---
--- Begin Message ---
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 ---
--- Begin Message ---
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
--- End Message ---
--- Begin Message ---
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="subject">Subject of email:</label><br />
> <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="subject">Subject of email </label><br/>
<input id="subject" name="subject" type="text"
value="'.$subject.'"><br/>
--
</Daniel P. Brown>
Network Infrastructure Manager
http://www.php.net/
--- End Message ---
--- Begin Message ---
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="subject">Subject of email:</label><br />
> <input id="subject" name="subject" type="text" value="<?php
> echo $subject;?>"><br />
> <label for="elvismail">Body of email:</label><br />
> <textarea id="elvismail" name="elvismail" rows="8"
> cols="40">"<?php echo $text;?>" </textarea><br />
> <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
--- End Message ---
--- Begin Message ---
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
--- End Message ---
--- Begin Message ---
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?
Ron
Ron Piggott
www.TheVerseOfTheDay.info
--- End Message ---
--- Begin Message ---
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/
--- End Message ---
--- Begin Message ---
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
--- End Message ---
--- Begin Message ---
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.
--- End Message ---
--- Begin Message ---
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/
--- End Message ---
--- Begin Message ---
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.
--- End Message ---
--- Begin Message ---
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-gene...@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
--- End Message ---
--- Begin Message ---
$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
--- End Message ---
--- Begin Message ---
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
--- End Message ---
--- Begin Message ---
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
--- End Message ---
--- Begin Message ---
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
--- End Message ---
--- Begin Message ---
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/
--- End Message ---
--- Begin Message ---
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('Ch&teau');
Yields this:
Château
Ch&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).
--- End Message ---