Stuck with preg_replace

Posted on 16th Feb 2014 by admin

Hi,

I'm trying to use preg_replace to remove part of the IP address submitted using a form on my website. The full IP is entered into my SQL database, but when printing it on the website I want to remove some numbers, so turn for example: 82.132.196.45 into 82.132.***.** when printed on the page.

I find preg_replace very hard to use, though, and the PHP manual isn't very helpful for those who don't know what all the /wd<>\n type things mean. I need to not only match numerals and replace each numeral with an asterisk, but get preg_replace to ignore the first two groups of numbers. I know this means telling the function to only pay attention to anything after the second dot, but don't know how.

Can anyone assist please?

Other forums