PHP Function To Check If String Contain Bad Words or Not


PHP Function To Check If String Contain Bad Words or Not

PHP Filter String


Here is a function Created For You To Check if string Contains Bad Word,Abusive Word or Not.

Code:-
<?php
function badword($text){
$bad = array('bad','lips','somebadword');
$rep = array('***','***','***','***');
//You Can More Bad Words in Array According To What You want filter
$text2 = str_replace($bad, $rep, $text);


if ($text != $text2)
{
return "bad";
}
else
{
return "good";
}
}

$text = "hello bad";
echo badword($text);
//Return Good Or Bad According To Text.
?>
Thanks.
2

PHP To Get Current User (Client) IP Address


PHP To Get Current User (Client) IP Address

php get user ip


Some Times We Need To Get Our Current User Ip Address Here is a PHP function We can Get the user ip easily without doing anything just call the function.

Code : -
<?php
function ip_address()
{
foreach (array('HTTP_CLIENT_IP',
'HTTP_X_FORWARDED_FOR',
'HTTP_X_FORWARDED',
'HTTP_X_CLUSTER_CLIENT_IP',
'HTTP_FORWARDED_FOR',
'HTTP_FORWARDED',
'REMOTE_ADDR') as $key){
if (array_key_exists($key, $_SERVER) === true)
{
foreach (explode(',', $_SERVER[$key]) as $ipaddress)
{
$ipaddress = trim($ipaddress); // Just to be safe

if (filter_var($ipaddress,
FILTER_VALIDATE_IP,
FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE)
!== false) {

return $ipaddress;
}
}
}
}
}
echo ip_address();

Thanks.
2