Jump to content

Backwards substr()?


Liquid Fire

Recommended Posts

I was wondering if there is a function that does the same thing as  substr but starts from the end so when i did substr($string, 0, 4) i would get the last four characters of the string.  I know i can do the following to get the last four characters:

<?php
$last_character = (strlen($string) - 1);
$first_character = ($last_character - 4);

$sub_string = substr($string, $first_character, $last_character);
?>

However if there is something that already does this i rather use that, if not i will just build this function into my file that has all my common functions.

Link to comment
https://forums.phpfreaks.com/topic/47902-backwards-substr/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.