Substrings

We’ve had some requests come in for a way to only show a certain number of characters in a string or to only display the last few characters.  For example, you might want to mask a credit card number with X’s and only show the last 4 digits of the card number.  To make this happen, we have written a function that generates a substring of a variable.

To use this function, simply put “|substr:start:length” after your variable name.  Start and Length are both numbers and indicate the starting point for the substring and the length of the substring .

Here are some examples:

($variable = 1234567890)

{$variable|substr:5} = 67890

{$variable|substr:0:5} = 12345

{$variable|substr:-4} = 7890   (this is useful if you only want last X number of characters)

If you have any other ideas/needs for custom formatting or other customized functions, please contact us and we’ll see what we can do!

Have more questions? Submit a request

0 Comments

Please sign in to leave a comment.
Powered by Zendesk