Re: [PHP] Str to Int

2006-01-21 Thread Rick Emery

Quoting [EMAIL PROTECTED]:


3. if ($cardID = '' || is_int($cardID))
   As someone mentioned, $cardID = '' makes an assignment, doesn't   
test for true/false.  Change to $cardID == ''.  And this statement   
SHOULD come up true as a whole because $cardID = '' should always   
be true (unless the assignment fails). So regardless of   
is_int($cardID) succeeding or failing, $cardID = '' should be true   
so this statement will always be true.


A trick I read about during my time of learning best practices: if  
comparing against a literal or constant, place the literal or constant  
on the left side of the expression. For example,


if ('' == $cardID) {

instead of

if ($cardID == '') {

That way, if you accidentally use = instead of ==, you should get  
an error because you can't assign something to a literal or constant.


Hope this helps somebody,
Rick
--
Rick Emery

When once you have tasted flight, you will forever walk the Earth
 with your eyes turned skyward, for there you have been, and there
 you will always long to return
  -- Leonardo Da Vinci

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



[PHP] Str to Int

2006-01-20 Thread Ron Eggler (Paykiosks)
Hi,

I need to do a type cast from string to int in folllowing code:
[php]
getPIN cardID='.intval(trim($cardID)).' quantity=1 /
[/php]
I need $cardID have converted to int. I thought it should work that way
but it does not!
But it's working if I'm putting
[php]
getPIN cardID=180 quantity=1 /
[/php]
in there. I got card ID as a var that is passed as get like:
[php]
$cardID = $HTTP_GET_VARS[cardID];
[/php]

Can anyone help me in that issue? Thank you!

__

Ron Eggler
Intern 
866-999-4179
www.paykiosks.net




Re: [PHP] Str to Int

2006-01-20 Thread Ray Hauge
You should be able to typecast the variable like so:

$cardID = (int)$cardID;

You can also check which type it is showing up as with the function gettype():

http://www.php.net/manual/en/function.gettype.php

Optionally you could use settype() to change the type of the variable:

http://www.php.net/manual/en/function.settype.php

HTH

-- 
Ray Hauge
Programmer/Systems Administrator
American Student Loan Services
http://www.americanstudentloan.com
1.800.575.1099

On Friday 20 January 2006 03:53 pm, Ron Eggler (Paykiosks) wrote:
 Hi,

 I need to do a type cast from string to int in folllowing code:
 [php]
 getPIN cardID='.intval(trim($cardID)).' quantity=1 /
 [/php]
 I need $cardID have converted to int. I thought it should work that way
 but it does not!
 But it's working if I'm putting
 [php]
 getPIN cardID=180 quantity=1 /
 [/php]
 in there. I got card ID as a var that is passed as get like:
 [php]
 $cardID = $HTTP_GET_VARS[cardID];
 [/php]

 Can anyone help me in that issue? Thank you!

 __

 Ron Eggler
 Intern
 866-999-4179
 www.paykiosks.net

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



Re: [PHP] Str to Int

2006-01-20 Thread Gerry Danen
You probably want to do an is_int() first...

After that, you know it's an int and treat it that way. Why do you need to
typecast it?

BTW, change $cardID = $HTTP_GET_VARS[cardID]; to $cardID = $_GET['cardID'];
for PHP5 compatibility... ;-)

Gerry

On 1/20/06, Ron Eggler (Paykiosks) [EMAIL PROTECTED] wrote:

 Hi,

 I need to do a type cast from string to int in folllowing code:
 [php]
 getPIN cardID='.intval(trim($cardID)).' quantity=1 /
 [/php]
 I need $cardID have converted to int. I thought it should work that way
 but it does not!
 But it's working if I'm putting
 [php]
 getPIN cardID=180 quantity=1 /
 [/php]
 in there. I got card ID as a var that is passed as get like:
 [php]
 $cardID = $HTTP_GET_VARS[cardID];
 [/php]

 Can anyone help me in that issue? Thank you!

 __

 Ron Eggler
 Intern
 866-999-4179
 www.paykiosks.net






--
Gerry
http://portal.danen.org/


Re: [PHP] Str to Int

2006-01-20 Thread Ron Eggler (Paykiosks)
Am Freitag, den 20.01.2006, 16:08 -0700 schrieb Gerry Danen:
 You probably want to do an is_int() first...
 
 After that, you know it's an int and treat it that way. Why do you
 need to typecast it?
 
 BTW, change $cardID = $HTTP_GET_VARS[cardID]; to $cardID =
 $_GET['cardID']; for PHP5 compatibility... ;-) 
 
 Gerry
Hey, it seems to be recognied by is_int() as integer. I have following
code:
[php]
  if ($HTTP_GET_VARS) // if some GET variables were passed on,...
  {
  switch ($HTTP_GET_VARS['action'])// recognize the get-var 'action'
{
case reserve:  // it says, 'reserve PINs'
  $cardID = $HTTP_GET_VARS['cardID']; // get cardID which was passed by GET 
as well
  if ($cardID=''||is_int($cardID)) // unless,
{
$cardID = intval($cardID.trim());
echo bERROR, cardID='' or cardID is no integer!/bbr\n; //print 
Error
exit(0); //and leave
}
  echo reservebr\n; // Variables were okay, so go ahead with the 
reserving
  / [reserve SKU] /
  $inputdata = 'xs:request xmlns:xs=\'urn:pinXpressSchema\' 
version=\'1.5\' langCode=\'en\''.$n.'
  DEALERinfo aspName='.$aspName.' 
   dealerName='.$dealerName.'
   posName='.$posName.'
   posPassword='.$posPassword.'
   userName='.$userName.'
   userPassword='.$userPassword.'/
  reservePINs
   getPIN cardID='.intval(trim($cardID)).' quantity=1 /
  /reservePINs
  /xs:request';
  / [/reserve SKU] ***/
break;
[/php]

it doesn't work that way but if I replace ['.intval(trim($cardID)).']
with [180] (everything between the []-brakets) it seems to work and
cardID was passed with the URL:
http://localhost/ewi.php?action=reservecardID=180
So what the hell is going wrong?
Thank you!

chEErs roN

 
 On 1/20/06, Ron Eggler (Paykiosks) [EMAIL PROTECTED] wrote:
 Hi,
 
 I need to do a type cast from string to int in folllowing
 code:
 [php]
 getPIN cardID='.intval(trim($cardID)).' quantity=1 /
 [/php]
 I need $cardID have converted to int. I thought it should work
 that way 
 but it does not!
 But it's working if I'm putting
 [php]
 getPIN cardID=180 quantity=1 /
 [/php]
 in there. I got card ID as a var that is passed as get like:
 [php]
 $cardID = $HTTP_GET_VARS[cardID]; 
 [/php]
 
 Can anyone help me in that issue? Thank you!
 
 __
 
 Ron Eggler
 Intern
 866-999-4179
 www.paykiosks.net
 
 
 
 
 
 
 -- 
 Gerry
 http://portal.danen.org/

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



Re: [PHP] Str to Int

2006-01-20 Thread comex
 if ($cardID=''||is_int($cardID))

Two problems with that statement:
First of all, this statement _sets_ cardID to '', and then (I think)
returns a false value since '' doesn't evaluate to true.  You probably
wanted ==.
Second of all, now that $cardID is '', it certainly isn't an int.  It
isn't an int, and it wouldn't be an int if you fixed that statement
because is_int only tests if it is, actually, an integer. 
$HTTP_GET_VARS['cardID'] could be '123', but it can't be 123 and so
that will be false.  From the PHP manual:

Note:  To test if a variable is a number or a numeric string (such
as form input, which is always a string), you must use is_numeric().

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



Re: [PHP] Str to Int

2006-01-20 Thread adriano ghezzi
well I don't well understand the problem hope these two snippets can solve
your problem: i tested them seems fine

file 1 form.php

html

head
meta http-equiv=Content-Language content=it
meta http-equiv=Content-Type content=text/html; charset=windows-1252
titleenter tour code/title
/head

body

pnbsp;/p
penter tour code/p
form method=POST action=get_card.php
 table border=1 width=47% id=table1
  tr
   td width=186user/td
   tdinput type=text name=txt_user size=20/td
  /tr
  tr
   td width=186code/td
   tdinput type=text name=txt_id size=20/td
  /tr
  tr
   td colspan=2
   p align=centerinput type=submit value=Invia name=B1
   input type=reset value=Reimposta name=B2/td
  /tr
 /table
 p dir=ltrnbsp;/p
/form
pnbsp;/p

/body

/html



file 2
--

get_card.php

html

head
meta http-equiv=Content-Type content=text/html; charset=windows-1252
titleNuova pagina 1/title
/head

body

?php

print string value:::.$_POST['txt_id'].br;

$int_id=intval(trim($_POST['txt_id']));

print integer value:::$int_id.br;

print type returned:.gettype($int_id).br;

?


/body

/html











2006/1/20, Ron Eggler (Paykiosks) [EMAIL PROTECTED]:

 Hi,

 I need to do a type cast from string to int in folllowing code:
 [php]
 getPIN cardID='.intval(trim($cardID)).' quantity=1 /
 [/php]
 I need $cardID have converted to int. I thought it should work that way
 but it does not!
 But it's working if I'm putting
 [php]
 getPIN cardID=180 quantity=1 /
 [/php]
 in there. I got card ID as a var that is passed as get like:
 [php]
 $cardID = $HTTP_GET_VARS[cardID];
 [/php]

 Can anyone help me in that issue? Thank you!

 __

 Ron Eggler
 Intern
 866-999-4179
 www.paykiosks.net






Re: [PHP] Str to Int

2006-01-20 Thread Ron Eggler (Paykiosks)
Am Freitag, den 20.01.2006, 18:28 -0500 schrieb comex:
  if ($cardID=''||is_int($cardID))
 
 Two problems with that statement:
 First of all, this statement _sets_ cardID to '', and then (I think)
 returns a false value since '' doesn't evaluate to true.  You probably
 wanted ==.

hOOps that's right, shit, haven't seen that..hm okay, it
works fine now, thanks again!

 Second of all, now that $cardID is '', it certainly isn't an int.  It
 isn't an int, and it wouldn't be an int if you fixed that statement
 because is_int only tests if it is, actually, an integer. 
 $HTTP_GET_VARS['cardID'] could be '123', but it can't be 123 and so
 that will be false.  From the PHP manual:
 
 Note:  To test if a variable is a number or a numeric string (such
 as form input, which is always a string), you must use is_numeric().
 

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



Re: [PHP] Str to Int

2006-01-20 Thread tg-php
Ok, some good points where made already, but let's pull it all together:

1. You should get in the habit of using $_GET[] instead of $HTTP_GET_VARS.. 
minor thing but worth noting (info at http://us2.php.net/reserved.variables)

2. case reserve:
   This, I believe, will treate reserve as a constant.  Change it to:
 case reserve:
   to make it work properly.

3. if ($cardID = '' || is_int($cardID))
   As someone mentioned, $cardID = '' makes an assignment, doesn't test for 
true/false.  Change to $cardID == ''.  And this statement SHOULD come up true 
as a whole because $cardID = '' should always be true (unless the assignment 
fails). So regardless of is_int($cardID) succeeding or failing, $cardID = '' 
should be true so this statement will always be true.

4. $cardID = intval($cardID.trim())
   Mixing PHP and Javascript? (or another language?).  Try:
   $cardID = intval($cardID);
   trim() probably isn't necessary unless your variable starts with letters.
   intval(123 main street) should give you 123.
   intval(main street suite 400) should give you 0 (zero)

5. intval() returns zero if it's a bad entry, so is_int(intval($anything)) 
should always be true I believe.  Just something to keep in mind in case 
$cardID zero is actually something you want to use.  In that case you don't 
want to use $cardID = intval($whatever) because you'll end up with zero.

6. exit(0)
   Again remnants from another language.  exit() works in PHP but no need to 
return a zero return value.  exit() is fine.

7. echo reserve is going to output reserve, not the value of a variable
   try echo $reserve;


Also.. it's probably not necessary, but I usually enclose my switch statements 
in braces just to keep it clear what's part of the switch.

switch ($somevar) {
  case val1:
echo Value one;
break;
  case val2:
echo Value two;
break;
  default:
echo No valid value;
break;
}

Good luck Ron!  You'll get ahold of this stuff soon enough.  Looks like you 
have some experience in other languages (and some of it will work fine in PHP.. 
it's very forgiving and flexible, but some of it will need to be tweaked).

Let us know if you have further questions.

-TG


= = = Original message = = =

[php]
  if ($HTTP_GET_VARS) // if some GET variables were passed on,...
  
  switch ($HTTP_GET_VARS['action'])// recognize the get-var 'action'

case reserve:  // it says, 'reserve PINs'
  $cardID = $HTTP_GET_VARS['cardID']; // get cardID which was passed by GET 
as well
  if ($cardID=''||is_int($cardID)) // unless,

$cardID = intval($cardID.trim());
echo bERROR, cardID='' or cardID is no integer!/bbr\n; //print 
Error
exit(0); //and leave

  echo reservebr\n; // Variables were okay, so go ahead with the 
reserving
  / [reserve SKU] /
  $inputdata = 'xs:request xmlns:xs=\'urn:pinXpressSchema\' 
version=\'1.5\' langCode=\'en\''.$n.'
  DEALERinfo aspName='.$aspName.' 
~   dealerName='.$dealerName.'
   posName='.$posName.'
   posPassword='.$posPassword.'
   userName='.$userName.'
   userPassword='.$userPassword.'/
  reservePINs
   getPIN cardID='.intval(trim($cardID)).' quantity=1 /
  /reservePINs
  /xs:request';
  / [/reserve SKU] ***/
break;
[/php]


___
Sent by ePrompter, the premier email notification software.
Free download at http://www.ePrompter.com.

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