Forums

[resolved] Get template tags as PHP (3 posts)

  1. aldeasim
    Member
    Posted 5 years ago #

    Hi there.
    I've been using WordPress in a chilean blogs community website some months ago and I think it's just awesome.

    Recently I have tried a method to show the IP of the author of every comment. I know there is a template tag called comment_author_IP(); and that's not a problem at all. My question is: How can I substring this tag to get only the first three groups of numbers and hide the last to protect the IP from abuses? I'm tring to get something like 255.255.255.x

    I've tried using substr(); PHP method, but it only returns the full IP, and no processes it at all. How can I manage that?

  2. Otto
    Tech Ninja
    Posted 5 years ago #

    This should work:

    <?php
    echo preg_replace('|(.*)\.(.*)\.(.*)\.(.*)|', '$1.$2.$3.xxx', get_comment_author_IP());
    ?>
  3. aldeasim
    Member
    Posted 5 years ago #

    Thanks Otto, it worked ;)

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.