php-general Digest 3 Jul 2012 18:24:46 -0000 Issue 7876

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

php-general Digest 3 Jul 2012 18:24:46 - Issue 7876

Topics (messages 318382 through 318389):

Re: How does this code work?
318382 by: Jim Lucas
318383 by: Robert Williams
318385 by: tamouse mailing lists

Re: PDO Prevent duplicate field names?
318384 by: tamouse mailing lists

Re: Destructor not called when extending SimpleXMLElement
318386 by: Nick Chalk

Re: Way to test if variable contains valid date
318387 by: shiplu
318388 by: Erwin Poeze

exec to launch putty.exe for telnet
318389 by: Devang Patel

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 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).




---End Message---
---BeginMessage---
On Jul 2, 2012, at 22:15, Jim Lucas li...@cmsws.com wrote:

 I think you missed something here...

 The above function uses strtr() not strstr()

Wow. I knew there had to be a simple, logical explanation (there was), that it 
would likely be one of those stupid things that I'd spot in two seconds the 
next morning (it was). That didn't stop me, however, from spending the last few 
hours hashing it over in the back of my mind, trying to figure out what magical 
power could make strstr() return content that is not in the haystack.

I feel like an idiot now, but at the same time, I am greatly relieved that all 
is right with the world, that the logic I've grown so accustomed to in thirty 
years of programming had not gone to voodoo. Thank you for that :-).

Hmm, I wonder if those thirty years are having a different sort of impact on 
me, in the form of decaying eyesight

--
Bob Williams

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 

Re: [PHP] How does this code work?

2012-07-03 Thread Robert Williams
On Jul 2, 2012, at 22:15, Jim Lucas li...@cmsws.com wrote:

 I think you missed something here...

 The above function uses strtr() not strstr()

Wow. I knew there had to be a simple, logical explanation (there was), that it 
would likely be one of those stupid things that I'd spot in two seconds the 
next morning (it was). That didn't stop me, however, from spending the last few 
hours hashing it over in the back of my mind, trying to figure out what magical 
power could make strstr() return content that is not in the haystack.

I feel like an idiot now, but at the same time, I am greatly relieved that all 
is right with the world, that the logic I've grown so accustomed to in thirty 
years of programming had not gone to voodoo. Thank you for that :-).

Hmm, I wonder if those thirty years are having a different sort of impact on 
me, in the form of decaying eyesight

--
Bob Williams

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



Re: [PHP] PDO Prevent duplicate field names?

2012-07-03 Thread tamouse mailing lists
On Mon, Jul 2, 2012 at 5:38 PM, Scott Baker bak...@canbytel.com wrote:
 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.

This is just not a province of PHP. What sort of behaviour would one
expect PHP to do given this scenario? It is surely not an error in
every case; I can see some code relying on this exact behaviour.
Making it some sort of option in PHP increases the complexity a great
deal, not only in trying to determine how to design and then *change*
the API to accommodate it, but in figuring out what exactly one might
*do*. Since SQL is a completely separate language from PHP, it makes
much more sense to learn to deal with these thing separately, and
understand what your SQL is doing. Indeed, SQL will happily return
multiple columns with the same column name; you must be aware of this
when writing it.

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



Re: [PHP] How does this code work?

2012-07-03 Thread tamouse mailing lists
On Tue, Jul 3, 2012 at 2:31 AM, Robert Williams rewilli...@thesba.com wrote:
 On Jul 2, 2012, at 22:15, Jim Lucas li...@cmsws.com wrote:
 Hmm, I wonder if those thirty years are having a different sort of impact on 
 me, in the form of decaying eyesight

I've had to tweak up the default fonts on things... *sigh*

-- 
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-03 Thread Nick Chalk
Thanks Erwin and Matijn.

On 2 July 2012 17:32, Matijn Woudt tijn...@gmail.com wrote:
 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).

Yes, that sounds plausible. As a quick hack, I tried adding a
destructor to the SimpleXMLElement extension, but that wasn't called
either.

I'll submit a bug report.

 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.

I've been playing with that today, and it looks like a workable solution.

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

2012-07-03 Thread shiplu


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


There is no such function or facility in php. However you can check date in
string by DateTime object also

try {
$date = new DateTime('2000-01-01');
} catch (Exception $e) {
echo $e-getMessage();
exit(1);
}

Check php.net/datetime.construct

-- 
Shiplu.Mokadd.im
ImgSign.com | A dynamic signature machine
Innovation distinguishes between follower and leader


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

2012-07-03 Thread Erwin Poeze
Or you could use a regular expression:

$probe = '2000-01-01';
$found = preg_match('/(19|20)\d\d[- \.](0[1-9]|1[012])[-
\.](0[1-9]|[12][0-9]|3[01])/', $probe);
var_dump($found==1);

Erwin

2012/7/3 shiplu shiplu@gmail.com

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


 There is no such function or facility in php. However you can check date in
 string by DateTime object also

 try {
 $date = new DateTime('2000-01-01');
 } catch (Exception $e) {
 echo $e-getMessage();
 exit(1);
 }

 Check php.net/datetime.construct

 --
 Shiplu.Mokadd.im
 ImgSign.com | A dynamic signature machine
 Innovation distinguishes between follower and leader



[PHP] exec to launch putty.exe for telnet

2012-07-03 Thread Devang Patel
Hello Experts,

I have putty.exe on my desktop so if I will go to command prompt and then
to  C:\Documents and Settings\user\Desktop location and execute following
command it will launch the Putty window of telnet connection to server
specified:

 putty.exe telnet://10.3.215.15/



I am trying to launch the putty to telnet to specific server using
following but its not working for me:

?php
$securecrt = C:\\Documents and Settings\\user\\Desktop\\putty.exe telnet://
10.3.215.15/ ;


exec($securecrt);
?

If I try following then it launches the putty application but will have to
provide the host name or IP to login:

?php
$securecrt = C:\\Documents and Settings\\user\\Desktop\\putty.exe ;


exec($securecrt);
?

Not sure if I am missing something very basic, It will be great if someone
can help with this.

Thanks,
Devang


Re: [PHP] exec to launch putty.exe for telnet

2012-07-03 Thread Matijn Woudt
On Tue, Jul 3, 2012 at 8:24 PM, Devang Patel devan...@gmail.com wrote:
 Hello Experts,

 I have putty.exe on my desktop so if I will go to command prompt and then
 to  C:\Documents and Settings\user\Desktop location and execute following
 command it will launch the Putty window of telnet connection to server
 specified:

  putty.exe telnet://10.3.215.15/



 I am trying to launch the putty to telnet to specific server using
 following but its not working for me:

 ?php
 $securecrt = C:\\Documents and Settings\\user\\Desktop\\putty.exe telnet://
 10.3.215.15/ ;


 exec($securecrt);
 ?

 If I try following then it launches the putty application but will have to
 provide the host name or IP to login:

 ?php
 $securecrt = C:\\Documents and Settings\\user\\Desktop\\putty.exe ;


 exec($securecrt);
 ?

 Not sure if I am missing something very basic, It will be great if someone
 can help with this.

 Thanks,
 Devang

Hi Devang,

What version of PHP are you using? It seems there is a bug with PHP
version 5.2 and lower on windows which requires you to add extra
quotes to the input, though, doing so will result in errors on PHP
version 5.3 and up.
Also, are you getting any specific errors? Maybe you can explain a
little more detailed of what isn't working exactly?

- Matijn

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