0

I have a quick question. How do I get only the last 4 digits of the cc_number? Will the following work? Or should I try something different..

Oh and I am emailing to myself that's why it has $message.

Here's the code I think will work:

$message .= "<td>{$_GET['cc_number'] = "XXXX-XXXX-XXXX-" . substr($cc_number,-4,4)}</td>";

Edited by drewpark88: n/a

3
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by drewpark88
1

Inside a complex syntax brackets ( {$var} ) you can call any function with a return value that can be converted to casted to a string. So using your code that would be:

$message .= "<td>XXXX-XXXX-XXXX-{substr($_GET['cc_number'] , -4, 4)}</td>";

//Or this....
$message .= "<td>XXXX-XXXX-XXXX-".substr($_GET['cc_number'] , -4, 4)."</td>";

//Or even this...
$message .= "<td>XXXX-XXXX-XXXX-";
$message .= substr($_GET['cc_number'] , -4, 4);
$message .= "</td>";

The first or second ones make most sense to me, so I would chose one of them, but it's totally up to you!

Votes + Comments
Helped me alot!
0

Thanks for the help FlashCreations! I appreciate it :)

Inside a complex syntax brackets ( {$var} ) you can call any function with a return value that can be converted to casted to a string. So using your code that would be:

$message .= "<td>XXXX-XXXX-XXXX-{substr($_GET['cc_number'] , -4, 4)}</td>";

//Or this....
$message .= "<td>XXXX-XXXX-XXXX-".substr($_GET['cc_number'] , -4, 4)."</td>";

//Or even this...
$message .= "<td>XXXX-XXXX-XXXX-";
$message .= substr($_GET['cc_number'] , -4, 4);
$message .= "</td>";

The first or second ones make most sense to me, so I would chose one of them, but it's totally up to you!

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.