phpwebparse-urlstrrchr

PHP strrchr parse int


I've got a problem. This is my PHP code :

$extract = $query;
$extractpoint = strrchr($extract, ".");

So, $extract is a parse_url of my website address. Exemple : http://test.com?param.6

$extract = param.6 and $extractpoint = .6

BUT, I want a solution to have only the 6, without the point.

Can you help me with that ?


Solution

  • The easiest solution would be restructuring the URL. I that is not possible though you can use strpos to find the position of your specific character and then use substr to select the characters after it.

    $extract = 'param.6';
    echo substr($extract, strpos($extract, '.') + 1);
    

    Demo: https://3v4l.org/CudTAG

    (The +1 is because it returns the position of the match and you want to be one place past that)