riad
riad

Reputation: 7194

Get rest of the string after cutting last two string

i have a variable value which may contain

     309  
    1208
   31802

Now, i need to get 3/12/318. mean the rest part of the string after cutting last two string.how can i do it in php.

Upvotes: 1

Views: 70

Answers (2)

Niklesh Raut
Niklesh Raut

Reputation: 34914

Another way is dividing by 100

<?php
echo (int)(309/100)."\n";
echo (int)(1208/100)."\n";
echo (int)(31802/100)."\n";
?>

https://eval.in/628062

Upvotes: 2

rbr94
rbr94

Reputation: 2277

Do it like that:

substr($string, $start, $length)

substr($string, -3, (strlen($string)-2) * -1);

With this expression, you start at the third from last char of the string and select all the remaining chars to the beginning.

PHP-Documentation for substr: http://php.net/manual/de/function.substr.php

Upvotes: 2

Related Questions