PDA

View Full Version : Help with split/explode


rnawky
Sun 25th Apr '04, 12:38am
after getting the host by gethostbyaddr("xx.xx.xx.xx") i get the host name. How do i return only the last 2 things.

example this.is.a.test returns a.test
example blah.1.2.3.blah returns 3.blah

i tried using

$isp = explode(".",$host)

Then doing

$isp[2].".".$isp[3]

but not all of the hostnames have the same ammount of .'s in them. Please help

Thanks

eXplosive
Sun 25th Apr '04, 11:02am
Use this code.


<?php

$hostname = 'this.is.a.test';

$parts = explode('.', $hostname);

echo $parts[count($parts) - 2] . '.' . $parts[count($parts) - 1];

?>

rnawky
Mon 26th Apr '04, 6:38pm
Thanks