Truncate an IP address? - Programmers Heaven

Howdy, Stranger!

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

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Truncate an IP address?

KirillKirill Posts: 9Member
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

  • emperoremperor Posts: 59Member
    : 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.