Ask your own question, for FREE!
Computer Science 16 Online
OpenStudy (anonymous):

This PHP code I have does not out-put anything! What am I doing wrong? I am using MAMP and Safari on a Mac. Any ideas?

OpenStudy (anonymous):

This is the code I have. It is supposed to intake a string of data and take out the "-"'s and output it as a plain number. Thanks

OpenStudy (anonymous):

The code for those that don't like downloading: <!DOCTYPE> <html> <head> <title> "Validate Credit Card" </title> </head> <body> <?php $CreditCard = array(" ", "8910-1234-5678-6543", "0000-9123-4567-0123"); foreach ($CreditCard as $CardNumber) { if (empty($CardNumber)) echo "<p>This Credit Card Number is invalid because it contains an empty string.</p>"; else { $CreditCardNumber = $CardNumber; $CreditCardNumber = str_replace("-", "", $CreditCardNumber); $CreditCardNumber = str_replace(" ", "", $CreditCardNumber); if (!is_numberic($CreditCardNumber)) echo "<p>Credit Card Number " . $CreditCardNumber . " is not a valid Credit Card number because it contains a non-numeric character. </p>"; else echo "<p>Credit Card Number " . $CreditCardNumber . " is a valid Credit Card number.</p>"; } } ?> </body> </html> The first step is to make sure you've got all of your blocks surrounded by braces. It's not absolutely required if you're only executing a single line on the condition, but it is good practice and helps readability. Then you're doing a secondary unnecessary assignment of your local variable CardNumber into CreditCardNumber. Again it's not a forbidden practice and sometimes serves a purpose, but in this case it just over complicates your code. Make those changes and if your problem doesn't solve itself, your code should be simplified enough to where it jumps out at you.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!