php-general Digest 16 Mar 2013 07:55:12 -0000 Issue 8165
Topics (messages 320586 through 320605):
Re: variable type - conversion/checking
320586 by: Ashley Sheridan
320589 by: richard gray
320591 by: Jim Lucas
320592 by: tamouse mailing lists
320596 by: Ashley Sheridan
320598 by: Andrew Ballard
320599 by: Sebastian Krebs
320600 by: Sebastian Krebs
320601 by: Andrew Ballard
320602 by: Andrew Ballard
320603 by: Matijn Woudt
320604 by: tamouse mailing lists
Re: PHP context editor
320587 by: Ashley Sheridan
320593 by: tamouse mailing lists
320595 by: Curtis Maurand
320597 by: Curtis Maurand
Re: Accessing Files Outside the Web Root
320588 by: Ashley Sheridan
Re: PDO Transaction
320590 by: Lester Caine
320605 by: Simon Dániel
Re: rather a HTML Q; however 2-FRAME
320594 by: tamouse mailing lists
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 ---
On Fri, 2013-03-15 at 04:57 -0500, tamouse mailing lists wrote:
> On Fri, Mar 15, 2013 at 3:55 AM, Peter Ford <p...@justcroft.com> wrote:
> > On 15/03/13 06:21, Jim Lucas wrote:
> >>
> >> On 3/14/2013 4:05 PM, Matijn Woudt wrote:
> >>>
> >>> On Thu, Mar 14, 2013 at 11:44 PM, Jim Lucas <li...@cmsws.com> wrote:
> >>>
> >>>> On 03/14/2013 11:50 AM, Samuel Lopes Grigolato wrote:
> >>>>
> >>>>> Something like "if (is_numeric($var)&& $var == floor($var))" will do
> >>>>> the
> >>>>>
> >>>>> trick. I don't know if there's a better (more elegant) way.
> >>>>>
> >>>>>
> >>>>> On Thu, Mar 14, 2013 at 3:09 PM, Matijn Woudt<tijn...@gmail.com> wrote:
> >>>>>
> >>>>> On Thu, Mar 14, 2013 at 7:02 PM, georg<georg.chamb...@telia.com**>
> >>>>>>
> >>>>>> wrote:
> >>>>>>
> >>>>>> Hi,
> >>>>>>>
> >>>>>>>
> >>>>>>> I have tried to find a way to check if a character string is
> >>>>>>> possible to
> >>>>>>> test whether it is convertible to an intger !
> >>>>>>>
> >>>>>>> any suggestion ?
> >>>>>>>
> >>>>>>> BR georg
> >>>>>>>
> >>>>>>
> >>>>>>
> >>>>>> You could use is_numeric for that, though it also accepts floats.
> >>>>>>
> >>>>>> - Matijn
> >>>>>>
> >>>>>>
> >>>>>
> >>>> for that type of test I have always used this:
> >>>>
> >>>> if ( $val == (int)$val ) {
> >>>>
> >>>> http://www.php.net/manual/en/**language.types.integer.php#**
> >>>>
> >>>> language.types.integer.casting<http://www.php.net/manual/en/language.types.integer.php#language.types.integer.casting>
> >>>>
> >>>>
> >>>>
> >>> I hope you're not serious about this...
> >>>
> >>> When comparing a string and an int, PHP will translate the string to int
> >>> too, and of course they will always be equal then.
> >>> So:
> >>> $a = "abc";
> >>> if($a == (int)$a) echo "YES";
> >>> else echo "NO";
> >>> Will always return YES.
> >>>
> >>> - Matijn
> >>>
> >>
> >> Hmmmm... Interesting. Looking back at my code base where I thought I was
> >> doing that, turns out the final results were not that, but this:
> >>
> >> $value = "asdf1234";
> >>
> >> if ( $value === (string)intval($value) ) {
> >>
> >> Looking back at the OP's request and after a little further searching,
> >> it seems that there might be a better possible solution for what the OP
> >> is requesting.
> >>
> >> <?php
> >>
> >> $values = array("asdf1234", "123.123", "123");
> >>
> >> foreach ( $values AS $value ) {
> >>
> >> echo $value;
> >>
> >> if ( ctype_digit($value) ) {
> >> echo ' - is all digits';
> >> } else {
> >> echo ' - is NOT all digits';
> >> }
> >> echo '<br />'.PHP_EOL;
> >> }
> >>
> >> returns...
> >>
> >> asdf1234 - is NOT all digits
> >> 123.123 - is NOT all digits
> >> 123 - is all digits
> >>
> >> http://www.php.net/manual/en/function.ctype-digit.php
> >>
> >> An important note:
> >>
> >> This function expects a string to be useful, so for example passing in
> >> an integer may not return the expected result. However, also note that
> >> HTML forms will result in numeric strings and not integers. See also the
> >> types section of the manual.
> >>
> >> --
> >> Jim
> >>
> >
> > Integers can be negative too: I suspect your test would reject a leading
> > '-'...
>
>
> For my money, `is_numeric()` does just what I want.
>
The thing is, is_numeric() will not check if a string is a valid int,
but any valid number, including a float.
For something like this, wouldn't a regex be better?
if(preg_match('/^\-?\d+$/', $string))
echo int
Thanks,
Ash
http://www.ashleysheridan.co.uk
--- End Message ---
--- Begin Message ---
On 15/03/2013 22:00, Ashley Sheridan wrote:
On Fri, 2013-03-15 at 04:57 -0500, tamouse mailing lists wrote:
For my money, `is_numeric()` does just what I want.
The thing is, is_numeric() will not check if a string is a valid int,
but any valid number, including a float.
For something like this, wouldn't a regex be better?
if(preg_match('/^\-?\d+$/', $string))
echo int
I'm late in on this thread so apologies if I have missed something here
.. but wouldn't is_int() do what the OP wants?
rich
--- End Message ---
--- Begin Message ---
On 03/15/2013 02:33 PM, richard gray wrote:
On 15/03/2013 22:00, Ashley Sheridan wrote:
On Fri, 2013-03-15 at 04:57 -0500, tamouse mailing lists wrote:
For my money, `is_numeric()` does just what I want.
The thing is, is_numeric() will not check if a string is a valid int,
but any valid number, including a float.
For something like this, wouldn't a regex be better?
if(preg_match('/^\-?\d+$/', $string))
echo int
I'm late in on this thread so apologies if I have missed something here
.. but wouldn't is_int() do what the OP wants?
rich
Nope, because the OP wants to test if a variable, that is a string,
could be converted to an integer. Not if a variable is an integer.
--
Jim Lucas
http://www.cmsws.com/
http://www.cmsws.com/examples/
--- End Message ---
--- Begin Message ---
On Fri, Mar 15, 2013 at 4:00 PM, Ashley Sheridan
<a...@ashleysheridan.co.uk>wrote:
> **
> On Fri, 2013-03-15 at 04:57 -0500, tamouse mailing lists wrote:
>
> On Fri, Mar 15, 2013 at 3:55 AM, Peter Ford <p...@justcroft.com> wrote:
> > On 15/03/13 06:21, Jim Lucas wrote:
> >>
> >> On 3/14/2013 4:05 PM, Matijn Woudt wrote:
> >>>
> >>> On Thu, Mar 14, 2013 at 11:44 PM, Jim Lucas <li...@cmsws.com> wrote:
> >>>
> >>>> On 03/14/2013 11:50 AM, Samuel Lopes Grigolato wrote:
> >>>>
> >>>>> Something like "if (is_numeric($var)&& $var == floor($var))" will do
> >>>>> the
> >>>>>
> >>>>> trick. I don't know if there's a better (more elegant) way.
> >>>>>
> >>>>>
> >>>>> On Thu, Mar 14, 2013 at 3:09 PM, Matijn Woudt<tijn...@gmail.com> wrote:
> >>>>>
> >>>>> On Thu, Mar 14, 2013 at 7:02 PM, georg<georg.chamb...@telia.com**>
> >>>>>>
> >>>>>> wrote:
> >>>>>>
> >>>>>> Hi,
> >>>>>>>
> >>>>>>>
> >>>>>>> I have tried to find a way to check if a character string is
> >>>>>>> possible to
> >>>>>>> test whether it is convertible to an intger !
> >>>>>>>
> >>>>>>> any suggestion ?
> >>>>>>>
> >>>>>>> BR georg
> >>>>>>>
> >>>>>>
> >>>>>>
> >>>>>> You could use is_numeric for that, though it also accepts floats.
> >>>>>>
> >>>>>> - Matijn
> >>>>>>
> >>>>>>
> >>>>>
> >>>> for that type of test I have always used this:
> >>>>
> >>>> if ( $val == (int)$val ) {
> >>>>
> >>>> http://www.php.net/manual/en/**language.types.integer.php#**
> >>>>
> >>>> language.types.integer.casting<http://www.php.net/manual/en/language.types.integer.php#language.types.integer.casting>
> >>>>
> >>>>
> >>>>
> >>> I hope you're not serious about this...
> >>>
> >>> When comparing a string and an int, PHP will translate the string to int
> >>> too, and of course they will always be equal then.
> >>> So:
> >>> $a = "abc";
> >>> if($a == (int)$a) echo "YES";
> >>> else echo "NO";
> >>> Will always return YES.
> >>>
> >>> - Matijn
> >>>
> >>
> >> Hmmmm... Interesting. Looking back at my code base where I thought I was
> >> doing that, turns out the final results were not that, but this:
> >>
> >> $value = "asdf1234";
> >>
> >> if ( $value === (string)intval($value) ) {
> >>
> >> Looking back at the OP's request and after a little further searching,
> >> it seems that there might be a better possible solution for what the OP
> >> is requesting.
> >>
> >> <?php
> >>
> >> $values = array("asdf1234", "123.123", "123");
> >>
> >> foreach ( $values AS $value ) {
> >>
> >> echo $value;
> >>
> >> if ( ctype_digit($value) ) {
> >> echo ' - is all digits';
> >> } else {
> >> echo ' - is NOT all digits';
> >> }
> >> echo '<br />'.PHP_EOL;
> >> }
> >>
> >> returns...
> >>
> >> asdf1234 - is NOT all digits
> >> 123.123 - is NOT all digits
> >> 123 - is all digits
> >>
> >> http://www.php.net/manual/en/function.ctype-digit.php
> >>
> >> An important note:
> >>
> >> This function expects a string to be useful, so for example passing in
> >> an integer may not return the expected result. However, also note that
> >> HTML forms will result in numeric strings and not integers. See also the
> >> types section of the manual.
> >>
> >> --
> >> Jim
> >>
> >
> > Integers can be negative too: I suspect your test would reject a leading
> > '-'...
>
>
> For my money, `is_numeric()` does just what I want.
>
>
>
> The thing is, is_numeric() will not check if a string is a valid int, but
> any valid number, including a float.
>
> For something like this, wouldn't a regex be better?
>
> if(preg_match('/^\-?\d+$/', $string))
> echo int
>
> Thanks,
> Ash
> http://www.ashleysheridan.co.uk
>
>
>
That is so about is_numeric(), but once I know it's a numeric, coercing it
to just an int is easy. *Validating*, rather than just assuring, that a
string is an integer is another matter; if you need to give feedback to the
user, etc., in which case a Regex is better.
(One small nit, + is possible on integers, too.)
--- End Message ---
--- Begin Message ---
tamouse mailing lists <tamouse.li...@gmail.com> wrote:
>On Fri, Mar 15, 2013 at 4:00 PM, Ashley Sheridan
><a...@ashleysheridan.co.uk>wrote:
>
>> **
>> On Fri, 2013-03-15 at 04:57 -0500, tamouse mailing lists wrote:
>>
>> On Fri, Mar 15, 2013 at 3:55 AM, Peter Ford <p...@justcroft.com>
>wrote:
>> > On 15/03/13 06:21, Jim Lucas wrote:
>> >>
>> >> On 3/14/2013 4:05 PM, Matijn Woudt wrote:
>> >>>
>> >>> On Thu, Mar 14, 2013 at 11:44 PM, Jim Lucas <li...@cmsws.com>
>wrote:
>> >>>
>> >>>> On 03/14/2013 11:50 AM, Samuel Lopes Grigolato wrote:
>> >>>>
>> >>>>> Something like "if (is_numeric($var)&& $var == floor($var))"
>will do
>> >>>>> the
>> >>>>>
>> >>>>> trick. I don't know if there's a better (more elegant) way.
>> >>>>>
>> >>>>>
>> >>>>> On Thu, Mar 14, 2013 at 3:09 PM, Matijn
>Woudt<tijn...@gmail.com> wrote:
>> >>>>>
>> >>>>> On Thu, Mar 14, 2013 at 7:02 PM,
>georg<georg.chamb...@telia.com**>
>> >>>>>>
>> >>>>>> wrote:
>> >>>>>>
>> >>>>>> Hi,
>> >>>>>>>
>> >>>>>>>
>> >>>>>>> I have tried to find a way to check if a character string is
>> >>>>>>> possible to
>> >>>>>>> test whether it is convertible to an intger !
>> >>>>>>>
>> >>>>>>> any suggestion ?
>> >>>>>>>
>> >>>>>>> BR georg
>> >>>>>>>
>> >>>>>>
>> >>>>>>
>> >>>>>> You could use is_numeric for that, though it also accepts
>floats.
>> >>>>>>
>> >>>>>> - Matijn
>> >>>>>>
>> >>>>>>
>> >>>>>
>> >>>> for that type of test I have always used this:
>> >>>>
>> >>>> if ( $val == (int)$val ) {
>> >>>>
>> >>>> http://www.php.net/manual/en/**language.types.integer.php#**
>> >>>>
>> >>>>
>language.types.integer.casting<http://www.php.net/manual/en/language.types.integer.php#language.types.integer.casting>
>> >>>>
>> >>>>
>> >>>>
>> >>> I hope you're not serious about this...
>> >>>
>> >>> When comparing a string and an int, PHP will translate the string
>to int
>> >>> too, and of course they will always be equal then.
>> >>> So:
>> >>> $a = "abc";
>> >>> if($a == (int)$a) echo "YES";
>> >>> else echo "NO";
>> >>> Will always return YES.
>> >>>
>> >>> - Matijn
>> >>>
>> >>
>> >> Hmmmm... Interesting. Looking back at my code base where I thought
>I was
>> >> doing that, turns out the final results were not that, but this:
>> >>
>> >> $value = "asdf1234";
>> >>
>> >> if ( $value === (string)intval($value) ) {
>> >>
>> >> Looking back at the OP's request and after a little further
>searching,
>> >> it seems that there might be a better possible solution for what
>the OP
>> >> is requesting.
>> >>
>> >> <?php
>> >>
>> >> $values = array("asdf1234", "123.123", "123");
>> >>
>> >> foreach ( $values AS $value ) {
>> >>
>> >> echo $value;
>> >>
>> >> if ( ctype_digit($value) ) {
>> >> echo ' - is all digits';
>> >> } else {
>> >> echo ' - is NOT all digits';
>> >> }
>> >> echo '<br />'.PHP_EOL;
>> >> }
>> >>
>> >> returns...
>> >>
>> >> asdf1234 - is NOT all digits
>> >> 123.123 - is NOT all digits
>> >> 123 - is all digits
>> >>
>> >> http://www.php.net/manual/en/function.ctype-digit.php
>> >>
>> >> An important note:
>> >>
>> >> This function expects a string to be useful, so for example
>passing in
>> >> an integer may not return the expected result. However, also note
>that
>> >> HTML forms will result in numeric strings and not integers. See
>also the
>> >> types section of the manual.
>> >>
>> >> --
>> >> Jim
>> >>
>> >
>> > Integers can be negative too: I suspect your test would reject a
>leading
>> > '-'...
>>
>>
>> For my money, `is_numeric()` does just what I want.
>>
>>
>>
>> The thing is, is_numeric() will not check if a string is a valid int,
>but
>> any valid number, including a float.
>>
>> For something like this, wouldn't a regex be better?
>>
>> if(preg_match('/^\-?\d+$/', $string))
>> echo int
>>
>> Thanks,
>> Ash
>> http://www.ashleysheridan.co.uk
>>
>>
>>
>That is so about is_numeric(), but once I know it's a numeric, coercing
>it
>to just an int is easy. *Validating*, rather than just assuring, that a
>string is an integer is another matter; if you need to give feedback to
>the
>user, etc., in which case a Regex is better.
>
>(One small nit, + is possible on integers, too.)
The op wasn't about casting a string to an int but detecting if a string was
just a string representation of an int. Hence using a regex to determine that.
Regular expressions are not just about giving feedback to the user.
Thanks,
Ash
http://www.ashleysheridan.co.uk
--- End Message ---
--- Begin Message ---
I suppose one could try something like this:
if (is_string($val) && $val === (string)(int)$val) ....
If $val is an integer masquerading as a string, it should be identical to
the original string when cast back to a string, shouldn't it? (I can't try
it right now.)
Andrew
--- End Message ---
--- Begin Message ---
2013/3/16 Ashley Sheridan <a...@ashleysheridan.co.uk>
>
>
> tamouse mailing lists <tamouse.li...@gmail.com> wrote:
>
> >On Fri, Mar 15, 2013 at 4:00 PM, Ashley Sheridan
> ><a...@ashleysheridan.co.uk>wrote:
> >
> >> **
> >> On Fri, 2013-03-15 at 04:57 -0500, tamouse mailing lists wrote:
> >>
> >> On Fri, Mar 15, 2013 at 3:55 AM, Peter Ford <p...@justcroft.com>
> >wrote:
> >> > On 15/03/13 06:21, Jim Lucas wrote:
> >> >>
> >> >> On 3/14/2013 4:05 PM, Matijn Woudt wrote:
> >> >>>
> >> >>> On Thu, Mar 14, 2013 at 11:44 PM, Jim Lucas <li...@cmsws.com>
> >wrote:
> >> >>>
> >> >>>> On 03/14/2013 11:50 AM, Samuel Lopes Grigolato wrote:
> >> >>>>
> >> >>>>> Something like "if (is_numeric($var)&& $var == floor($var))"
> >will do
> >> >>>>> the
> >> >>>>>
> >> >>>>> trick. I don't know if there's a better (more elegant) way.
> >> >>>>>
> >> >>>>>
> >> >>>>> On Thu, Mar 14, 2013 at 3:09 PM, Matijn
> >Woudt<tijn...@gmail.com> wrote:
> >> >>>>>
> >> >>>>> On Thu, Mar 14, 2013 at 7:02 PM,
> >georg<georg.chamb...@telia.com**>
> >> >>>>>>
> >> >>>>>> wrote:
> >> >>>>>>
> >> >>>>>> Hi,
> >> >>>>>>>
> >> >>>>>>>
> >> >>>>>>> I have tried to find a way to check if a character string is
> >> >>>>>>> possible to
> >> >>>>>>> test whether it is convertible to an intger !
> >> >>>>>>>
> >> >>>>>>> any suggestion ?
> >> >>>>>>>
> >> >>>>>>> BR georg
> >> >>>>>>>
> >> >>>>>>
> >> >>>>>>
> >> >>>>>> You could use is_numeric for that, though it also accepts
> >floats.
> >> >>>>>>
> >> >>>>>> - Matijn
> >> >>>>>>
> >> >>>>>>
> >> >>>>>
> >> >>>> for that type of test I have always used this:
> >> >>>>
> >> >>>> if ( $val == (int)$val ) {
> >> >>>>
> >> >>>> http://www.php.net/manual/en/**language.types.integer.php#**
> >> >>>>
> >> >>>>
> >language.types.integer.casting<
> http://www.php.net/manual/en/language.types.integer.php#language.types.integer.casting
> >
> >> >>>>
> >> >>>>
> >> >>>>
> >> >>> I hope you're not serious about this...
> >> >>>
> >> >>> When comparing a string and an int, PHP will translate the string
> >to int
> >> >>> too, and of course they will always be equal then.
> >> >>> So:
> >> >>> $a = "abc";
> >> >>> if($a == (int)$a) echo "YES";
> >> >>> else echo "NO";
> >> >>> Will always return YES.
> >> >>>
> >> >>> - Matijn
> >> >>>
> >> >>
> >> >> Hmmmm... Interesting. Looking back at my code base where I thought
> >I was
> >> >> doing that, turns out the final results were not that, but this:
> >> >>
> >> >> $value = "asdf1234";
> >> >>
> >> >> if ( $value === (string)intval($value) ) {
> >> >>
> >> >> Looking back at the OP's request and after a little further
> >searching,
> >> >> it seems that there might be a better possible solution for what
> >the OP
> >> >> is requesting.
> >> >>
> >> >> <?php
> >> >>
> >> >> $values = array("asdf1234", "123.123", "123");
> >> >>
> >> >> foreach ( $values AS $value ) {
> >> >>
> >> >> echo $value;
> >> >>
> >> >> if ( ctype_digit($value) ) {
> >> >> echo ' - is all digits';
> >> >> } else {
> >> >> echo ' - is NOT all digits';
> >> >> }
> >> >> echo '<br />'.PHP_EOL;
> >> >> }
> >> >>
> >> >> returns...
> >> >>
> >> >> asdf1234 - is NOT all digits
> >> >> 123.123 - is NOT all digits
> >> >> 123 - is all digits
> >> >>
> >> >> http://www.php.net/manual/en/function.ctype-digit.php
> >> >>
> >> >> An important note:
> >> >>
> >> >> This function expects a string to be useful, so for example
> >passing in
> >> >> an integer may not return the expected result. However, also note
> >that
> >> >> HTML forms will result in numeric strings and not integers. See
> >also the
> >> >> types section of the manual.
> >> >>
> >> >> --
> >> >> Jim
> >> >>
> >> >
> >> > Integers can be negative too: I suspect your test would reject a
> >leading
> >> > '-'...
> >>
> >>
> >> For my money, `is_numeric()` does just what I want.
> >>
> >>
> >>
> >> The thing is, is_numeric() will not check if a string is a valid int,
> >but
> >> any valid number, including a float.
> >>
> >> For something like this, wouldn't a regex be better?
> >>
> >> if(preg_match('/^\-?\d+$/', $string))
> >> echo int
> >>
> >> Thanks,
> >> Ash
> >> http://www.ashleysheridan.co.uk
> >>
> >>
> >>
> >That is so about is_numeric(), but once I know it's a numeric, coercing
> >it
> >to just an int is easy. *Validating*, rather than just assuring, that a
> >string is an integer is another matter; if you need to give feedback to
> >the
> >user, etc., in which case a Regex is better.
> >
> >(One small nit, + is possible on integers, too.)
>
> The op wasn't about casting a string to an int but detecting if a string
> was just a string representation of an int. Hence using a regex to
> determine that. Regular expressions are not just about giving feedback to
> the user.
>
Guess regex are the only useful solution here. When you consider to use
built-in functions, just remember, that for example '0xAF' is an integer
too, but '42.00' isn't.
>
> Thanks,
> Ash
> http://www.ashleysheridan.co.uk
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--
github.com/KingCrunch
--- End Message ---
--- Begin Message ---
2013/3/16 Andrew Ballard <aball...@gmail.com>
> I suppose one could try something like this:
>
> if (is_string($val) && $val === (string)(int)$val) ....
>
> If $val is an integer masquerading as a string, it should be identical to
> the original string when cast back to a string, shouldn't it? (I can't try
> it right now.)
>
It is semantically equivalent to
$val == (int) $val
and as far as I remember (I didn't read everything completely) this were
mentioned. I didn't read, whether or not, it was accepted as solution ;)
>
> Andrew
>
--
github.com/KingCrunch
--- End Message ---
--- Begin Message ---
On Mar 15, 2013 9:54 PM, "Sebastian Krebs" <krebs....@gmail.com> wrote:
>
> 2013/3/16 Andrew Ballard <aball...@gmail.com>
>>
>> I suppose one could try something like this:
>>
>> if (is_string($val) && $val === (string)(int)$val) ....
>>
>> If $val is an integer masquerading as a string, it should be identical to
>> the original string when cast back to a string, shouldn't it? (I can't
try
>> it right now.)
>
>
> It is semantically equivalent to
>
> $val == (int) $val
>
> and as far as I remember (I didn't read everything completely) this were
mentioned. I didn't read, whether or not, it was accepted as solution ;)
>
Not quite. That method will massage both values to the same type for the
comparison. Whoever shot it down said they both go to int. If that's the
case,
if ($val == (int)$val)
is more like saying
if ((int)$val === (int)$val)
What I suggested converts the string to an int, the resulting int back to a
string, then does a type-specific comparison to the original string value.
Andrew
--- End Message ---
--- Begin Message ---
> Guess regex are the only useful solution here. When you consider to use
> built-in functions, just remember, that for example '0xAF' is an integer
> too, but '42.00' isn't.
Shoot...I hadn't considered how PHP might handle hex or octal strings when
casting to int. (Again, not in front of a computer where I can test it
right now. )
Regexes have problems with more than 9 digits for 32-bit ints. I guess to
some degree it depends on how likely you are to experience values that
large.
Andrew
--- End Message ---
--- Begin Message ---
On Sat, Mar 16, 2013 at 2:54 AM, Sebastian Krebs <krebs....@gmail.com>wrote:
> 2013/3/16 Andrew Ballard <aball...@gmail.com>
>
> > I suppose one could try something like this:
> >
> > if (is_string($val) && $val === (string)(int)$val) ....
> >
> > If $val is an integer masquerading as a string, it should be identical to
> > the original string when cast back to a string, shouldn't it? (I can't
> try
> > it right now.)
> >
>
> It is semantically equivalent to
>
> $val == (int) $val
>
> and as far as I remember (I didn't read everything completely) this were
> mentioned. I didn't read, whether or not, it was accepted as solution ;)
>
>
Sebastian,
This is not true. $val === (string)(int)$val will do a string compare,
where as $val == (int) $val will do an integer compare, which will convert
the left hand to integer too. Your equation will always evaluate as true.
Andrews' solution should work too, but it depends on what you accept as
integer, in this case you would be able to parse normal numbers, with
optionally a sign and extra 0's in front.
is_numeric will parse those integers, but also hexadecimal, octal and
binary notations, and parses floating point integers. If you don't want the
floating points, you could add an extra check that verifies it is not a
float.
- Matijn
--- End Message ---
--- Begin Message ---
On Fri, Mar 15, 2013 at 8:34 PM, Ashley Sheridan
<a...@ashleysheridan.co.uk> wrote:
>>> >>>>> On Thu, Mar 14, 2013 at 7:02 PM,
>>georg<georg.chamb...@telia.com**>
>>> >>>>>>> I have tried to find a way to check if a character string is
>>> >>>>>>> possible to
>>> >>>>>>> test whether it is convertible to an intger !
> The op wasn't about casting a string to an int but detecting if a string was
> just a string representation of an int. Hence using a regex to determine
> that. Regular expressions are not just about giving feedback to the user.
Seemed to me that was exactly what it was about.
> Thanks,
> Ash
> http://www.ashleysheridan.co.uk
--- End Message ---
--- Begin Message ---
On Fri, 2013-03-15 at 12:05 +0100, Sebastian Krebs wrote:
> 2013/3/15 Karim Geiger <gei...@b1-systems.de>
>
> > Hi Georg,
> >
> > On Thu, 2013-03-14 at 23:10 +0100, georg wrote:
> > > hello,
> > > annyone knows of some good PHP context editor freeware ?
> > > (tired of missing out on trivials like ; )
> >
> > I don't know exactly what you mean by a context editor but if you want
> > an editor with syntax highlighting try eclipse for an complete IDE
> > (Multiplatform), notepad++ on Windows, textwrangler on Mac or vim on
> > Linux
> >
>
> Or PhpStorm on Linux (multiplatform) :) Or Netbeans on Linux
> (multiplatform too). Or gedit on Gnome/Linux, or or or ...
> "vim" is not the end of what can a linux desktop can provide :D
>
>
> >
> > Regards
> >
> > --
> > Karim Geiger
> >
> > B1 Systems GmbH
> > Osterfeldstraße 7 / 85088 Vohburg / http://www.b1-systems.de
> > GF: Ralph Dehner / Unternehmenssitz: Vohburg / AG: Ingolstadt,HRB 3537
> >
>
>
>
For Linux I quite like KATE, it's part of the KDE stuff. Netbeans is
great as a full-blown IDE, or Geany is quite nice if you need something
in-between those two. The great thing is that they are all available on
Windows too.
Thanks,
Ash
http://www.ashleysheridan.co.uk
--- End Message ---
--- Begin Message ---
On Fri, Mar 15, 2013 at 4:03 PM, Ashley Sheridan
<a...@ashleysheridan.co.uk> wrote:
> On Fri, 2013-03-15 at 12:05 +0100, Sebastian Krebs wrote:
>
>> 2013/3/15 Karim Geiger <gei...@b1-systems.de>
>>
>> > Hi Georg,
>> >
>> > On Thu, 2013-03-14 at 23:10 +0100, georg wrote:
>> > > hello,
>> > > annyone knows of some good PHP context editor freeware ?
>> > > (tired of missing out on trivials like ; )
>> >
>> > I don't know exactly what you mean by a context editor but if you want
>> > an editor with syntax highlighting try eclipse for an complete IDE
>> > (Multiplatform), notepad++ on Windows, textwrangler on Mac or vim on
>> > Linux
>> >
>>
>> Or PhpStorm on Linux (multiplatform) :) Or Netbeans on Linux
>> (multiplatform too). Or gedit on Gnome/Linux, or or or ...
>> "vim" is not the end of what can a linux desktop can provide :D
>>
>>
>> >
>> > Regards
>> >
>> > --
>> > Karim Geiger
>> >
>> > B1 Systems GmbH
>> > Osterfeldstraße 7 / 85088 Vohburg / http://www.b1-systems.de
>> > GF: Ralph Dehner / Unternehmenssitz: Vohburg / AG: Ingolstadt,HRB 3537
>> >
>>
>>
>>
>
>
> For Linux I quite like KATE, it's part of the KDE stuff. Netbeans is
> great as a full-blown IDE, or Geany is quite nice if you need something
> in-between those two. The great thing is that they are all available on
> Windows too.
>
> Thanks,
> Ash
> http://www.ashleysheridan.co.uk
>
>
Since we're doing this, lemme toss in my rec for Sublime Text 2.
But I'm still holding onto my dear old Emacs, cos it's my frenz.
--- End Message ---
--- Begin Message ---
I've been playing with bluefish as of late. The openoffice folks have taken
over that project.
tamouse mailing lists <tamouse.li...@gmail.com> wrote:
>On Fri, Mar 15, 2013 at 4:03 PM, Ashley Sheridan
><a...@ashleysheridan.co.uk> wrote:
>> On Fri, 2013-03-15 at 12:05 +0100, Sebastian Krebs wrote:
>>
>>> 2013/3/15 Karim Geiger <gei...@b1-systems.de>
>>>
>>> > Hi Georg,
>>> >
>>> > On Thu, 2013-03-14 at 23:10 +0100, georg wrote:
>>> > > hello,
>>> > > annyone knows of some good PHP context editor freeware ?
>>> > > (tired of missing out on trivials like ; )
>>> >
>>> > I don't know exactly what you mean by a context editor but if you
>want
>>> > an editor with syntax highlighting try eclipse for an complete IDE
>>> > (Multiplatform), notepad++ on Windows, textwrangler on Mac or vim
>on
>>> > Linux
>>> >
>>>
>>> Or PhpStorm on Linux (multiplatform) :) Or Netbeans on Linux
>>> (multiplatform too). Or gedit on Gnome/Linux, or or or ...
>>> "vim" is not the end of what can a linux desktop can provide :D
>>>
>>>
>>> >
>>> > Regards
>>> >
>>> > --
>>> > Karim Geiger
>>> >
>>> > B1 Systems GmbH
>>> > Osterfeldstraße 7 / 85088 Vohburg / http://www.b1-systems.de
>>> > GF: Ralph Dehner / Unternehmenssitz: Vohburg / AG: Ingolstadt,HRB
>3537
>>> >
>>>
>>>
>>>
>>
>>
>> For Linux I quite like KATE, it's part of the KDE stuff. Netbeans is
>> great as a full-blown IDE, or Geany is quite nice if you need
>something
>> in-between those two. The great thing is that they are all available
>on
>> Windows too.
>>
>> Thanks,
>> Ash
>> http://www.ashleysheridan.co.uk
>>
>>
>
>Since we're doing this, lemme toss in my rec for Sublime Text 2.
>
>But I'm still holding onto my dear old Emacs, cos it's my frenz.
>
>--
>PHP General Mailing List (http://www.php.net/)
>To unsubscribe, visit: http://www.php.net/unsub.php
--
Sent from my Android phone with K-9 Mail. Please excuse my brevity.
--- End Message ---
--- Begin Message ---
Sent from my Galaxy S®III
-------- Original message --------
From: Ashley Sheridan <a...@ashleysheridan.co.uk>
Date: 03/15/2013 5:03 PM (GMT-05:00)
To: Sebastian Krebs <krebs....@gmail.com>
Cc: gei...@b1-systems.de,georg <georg.chamb...@telia.com>,PHP General List
<php-gene...@lists.php.net>
Subject: Re: [PHP] PHP context editor
On Fri, 2013-03-15 at 12:05 +0100, Sebastian Krebs wrote:
> 2013/3/15 Karim Geiger <gei...@b1-systems.de>
>
> > Hi Georg,
> >
> > On Thu, 2013-03-14 at 23:10 +0100, georg wrote:
> > > hello,
> > > annyone knows of some good PHP context editor freeware ?
> > > (tired of missing out on trivials like ; )
> >
> > I don't know exactly what you mean by a context editor but if you want
> > an editor with syntax highlighting try eclipse for an complete IDE
> > (Multiplatform), notepad++ on Windows, textwrangler on Mac or vim on
> > Linux
> >
>
> Or PhpStorm on Linux (multiplatform) :) Or Netbeans on Linux
> (multiplatform too). Or gedit on Gnome/Linux, or or or ...
> "vim" is not the end of what can a linux desktop can provide :D
>
>
> >
> > Regards
> >
> > --
> > Karim Geiger
> >
> > B1 Systems GmbH
> > Osterfeldstraße 7 / 85088 Vohburg / http://www.b1-systems.de
> > GF: Ralph Dehner / Unternehmenssitz: Vohburg / AG: Ingolstadt,HRB 3537
> >
>
>
>
For Linux I quite like KATE, it's part of the KDE stuff. Netbeans is
great as a full-blown IDE, or Geany is quite nice if you need something
in-between those two. The great thing is that they are all available on
I've also been using something called Textpad on Windows. It's about 30 euros
and very powerful.
--- End Message ---
--- Begin Message ---
On Fri, 2013-03-15 at 09:11 -0400, Dale H. Cook wrote:
> At 09:44 PM 3/14/2013, tamouse mailing lists wrote:
>
> >If you are delivering files to a (human) user via their browser, by whatever
> >mechanism, that means someone can write a script to scrape them.
>
> That script, however, would have to be running on my host system in order to
> access the script which actually delivers the file, as the latter script is
> located outside of the web root.
>
> Dale H. Cook, Market Chief Engineer, Centennial Broadcasting,
> Roanoke/Lynchburg, VA
> http://plymouthcolony.net/starcityeng/index.html
>
>
Not really.
You script is web accessible right? It just opens a file and delivers it
to the browser of your visitor. It's easy to make a script that pretends
to be a browser and make the same request of your script to grab the
file.
Thanks,
Ash
http://www.ashleysheridan.co.uk
--- End Message ---
--- Begin Message ---
Simon Dániel wrote:
Hi,
I have a trouble with PDO transactions.
I would like to start using transactions, but I am not familiar with it. I
have got a 'There is no active transaction' exception, however, I am using
beginTransaction method, and also I have set PDO::ATTR_AUTOCOMMIT to false
right after connecting to the database.
In my whole code I have used the commit method only once.
Between beginTransaction and commit methods, as far as I know, I did not
use anything that could activate auto-commit. In my test code, there is
only an exec method of PDO, and an execute of PDOStatement. Maybe one of
these activated auto-commit?
And what are the possible commands which are able to activate auto-commit?
I know that the commit method can do that, but - as I already wrote - I
have issued it only once, and it is in the destructor of a singleton class.
So what could be the problem?
You don't say which database you are trying to access. Not all actually support
transactions, and some need a connection correctly set.
--
Lester Caine - G8HFL
-----------------------------
Contact - http://lsces.co.uk/wiki/?page=contact
L.S.Caine Electronic Services - http://lsces.co.uk
EnquirySolve - http://enquirysolve.com/
Model Engineers Digital Workshop - http://medw.co.uk
Rainbow Digital Media - http://rainbowdigitalmedia.co.uk
--- End Message ---
--- Begin Message ---
2013/3/15 Lester Caine <les...@lsces.co.uk>
> Simon Dániel wrote:
>
>> Hi,
>>
>> I have a trouble with PDO transactions.
>>
>> I would like to start using transactions, but I am not familiar with it. I
>> have got a 'There is no active transaction' exception, however, I am using
>> beginTransaction method, and also I have set PDO::ATTR_AUTOCOMMIT to false
>> right after connecting to the database.
>> In my whole code I have used the commit method only once.
>>
>> Between beginTransaction and commit methods, as far as I know, I did not
>> use anything that could activate auto-commit. In my test code, there is
>> only an exec method of PDO, and an execute of PDOStatement. Maybe one of
>> these activated auto-commit?
>>
>> And what are the possible commands which are able to activate auto-commit?
>> I know that the commit method can do that, but - as I already wrote - I
>> have issued it only once, and it is in the destructor of a singleton
>> class.
>>
>> So what could be the problem?
>>
>
> You don't say which database you are trying to access. Not all actually
> support transactions, and some need a connection correctly set.
I am using MySQL.
--- End Message ---
--- Begin Message ---
On Fri, Mar 15, 2013 at 10:36 AM, Jim Giner
<jim.gi...@albanyhandball.com> wrote:
> On 3/15/2013 10:11 AM, georg wrote:
>>
>> Actually I think you are right;
>>
>> what I would have liked (as a natural extension of the depression....:)
>> is actually a <FRAME> tag that stands without the <FRAMESET>
>> and which as target="framename" instead of the frame defining
>> name="framename"
>> and which just displayed the src in that frame (immediatly as it does
>> today)
>>
>> Im fairly new to PHP so Im bound to bounce into some walls, tnx.
>>
>> BR georg
>
>
> And apparently new to html as well if you want to use frames still :)
> Why not learn "just a little" css and html and develop something more
> current that you won't be re-visiting down the road some time and changing?
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
Although maybe there's something ascetic about going through features
from the beginning and learning to hate them as much as we did.
--- End Message ---