I need to get the last four characters of a string and store them in a variable called tax.
the string contains "Dublin0.07"
I want to store the last four characters in a variable named $tax so that $tax = 0.07 I am assuming that the decimal is considered a character.
I found this and it works but I'm sure there is a better way.
$str = "Dubline0.07";
$four = $str{strlen($str)-1};
$three = $str{strlen($str)-2};
$two = $str{strlen($str)-3};
$one = $str{strlen($str)-4};
$tax = "$one" . "$two" . "$three" . "$four";
When faced with a decision, always ask, 'Which would be the most fun?'
the string contains "Dublin0.07"
I want to store the last four characters in a variable named $tax so that $tax = 0.07 I am assuming that the decimal is considered a character.
I found this and it works but I'm sure there is a better way.
$str = "Dubline0.07";
$four = $str{strlen($str)-1};
$three = $str{strlen($str)-2};
$two = $str{strlen($str)-3};
$one = $str{strlen($str)-4};
$tax = "$one" . "$two" . "$three" . "$four";
When faced with a decision, always ask, 'Which would be the most fun?'