Truncate an IP address?

I need to truncate any IP address so that if I have

192.168.0.12

I end up with

192.168.0

any ideas what would be the best way to do this?

Comments

  • : I need to truncate any IP address so that if I have
    :
    : 192.168.0.12
    :
    : I end up with
    :
    : 192.168.0
    :
    : any ideas what would be the best way to do this?
    :

    I don't think there are any functions that deal with IP addresses, but for a simple thing like that you could use string functions - if $ip contains the address then $ip = substr ($ip, 0, strrpos ($ip, '.')) should work fine.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion