user3629794 user3629794 - 1 year ago 143
PHP Question

PHP split string

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

$ipadd = "";

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 Source

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);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download