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>";

Recommended Answers

All 3 Replies

$a = substr($_GET['cc_number'],-4,4);
echo $a;

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!

commented: Helped me alot! +1

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!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.