You are here: Re: [PHP] Str to Int « PHP « IT news, forums, messages
Re: [PHP] Str to Int

Posted by tg-php on 01/21/06 02:12

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

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";
case "val2":
echo "Value two";
echo "No valid value";

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.


= = = Original message = = =

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 "<b>ERROR, cardID='' or cardID is no integer!</b><br>\n"; //print Error
exit(0); //and leave

echo "reserve<br>\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.'"
<getPIN cardID="'.intval(trim($cardID)).'" quantity="1" />
/**************** [/reserve SKU] ***************/

Sent by ePrompter, the premier email notification software.
Free download at



[Reply to this message]

Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация