在php之后只显示三个字符

So i have reference numbers that look like this:

-76527921
O-2323232323
BPP-76527921
EEFS-23232323

I wish to output the three numbers after the -.

So in the first case it should output 765 and second 232 etc..

I have tried:

echo substr($ref["refno"], 3, 3);

But since the prefix (the BPP, O, EEFS or none in this example) is custom and can be more/less than three chars, it does not work right.

How can i do this?

Use strpos() to locate the first occurrence of - and add 3 to that for your substr().

if (!strpos(trim($ref['refno'], '-'), '-')) echo substr(trim($ref['refno'],'-'), 0,3);
else echo substr($ref['refno'], strpos($ref['refno'], '-')+1, 3);

my solution:

echo substr(end(explode("-",$ref['refno'],2)), 0, 3);

use explode() to make an array ('EEFS','23232323'), then select last part using end(), finally substract 3 chars using substr()