user3629794 user3629794 - 4 months ago 28
PHP Question

PHP split string

Hey how can I split string into 2 string, exemple:

$ipadd = "192.168.1.60";


From here I want to print 2 result,
one is: 192.168.1
secend is:60

Always split by the last point and print 2 string.

Answer

Everything after the last period:

echo substr(strrchr($ipadd, '.'), 1);

To get everything before it, you first need the position:

$pos = strrpos($ipadd, '.');
echo substr($ipadd, 0, $pos);