Hey Guys,

I need to send an HTML email with the last 4 digits of the credit card. Everything else sends fine but must be an error in my code, probably didn't do it right can someone correct me please : )

XXXX-XXXX-XXXX-".substr{$_REQUEST['cc_number'] , -4, 4}

* Yeah I know, new to PHP so it's probably not the right way to do it. I thought this would work : /

Recommended Answers

All 5 Replies

Almost right., the -4 needs to be -1 though.

A positive number will start from beginning of the string and return the number of characters specified, while a negative number to start from end of string.

In this case, you want to start with the last character(-1) and read 4 characters :)

Oh ok thanks, I tried that but I am still getting the following error:

Parse error: syntax error, unexpected '{'

Almost right., the -4 needs to be -1 though.

A positive number will start from beginning of the string and return the number of characters specified, while a negative number to start from end of string.

In this case, you want to start with the last character(-1) and read 4 characters :)

Ah, whoops, wrong brackets as well. Missed that on your first post :P

For functions, use standard braces ( and ).

Curly braces are for statements and function definitions.

So it should be substr($_REQUEST['cc_number'] , -1, 4)

commented: Will is awesome, helped a bunch! +1

Thanks Will, you are a life saver! I appreciate it :)

Ah, whoops, wrong brackets as well. Missed that on your first post :P

For functions, use standard braces ( and ).

Curly braces are for statements and function definitions.

So it should be substr($_REQUEST['cc_number'] , -1, 4)

Err, don't think the code Will posted is entirely right. You need:

substr($_REQUEST['cc_number'] , -4)

See http://www.php.net/substr for more info and examples.

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.