Tuesday, 17 November 2015

14_WORD CENSORING

WORD CENSORING


< ? Php
$find1=array(“harshida”,”parmar”,”jayshree”);
$replace1=array(“h*******a”,”p****r”,”j******e”);
If(isset($_POST[“user_input”]) && !empty($_POST[“user_input”])) {
//!empty () means NOT EMPTY…
$user_input=$POST[“user_input”]; $user_input_new=str_ireplace($find1,$replace1,$user_input);
echo $user_input_new;
}
? >



Name:


str_ireplace() function will automatically find the STRING EITHER IN UPPER OR LOWER CASE … CONFUSEEEE


$find1 array variable contain all the value in lower case and may be user enter the value either in upper or lower … so we have one solution either we can use strtolower() function to convert the user entered string in to lower… but what happen it will convert all the content into lower case …
So here str_ireplace() function came into the picture… str_ireplace function will check the user entered data contain any word which match to $find1 array variable value… If yes then check that value entered by user is in capital .. then only that work will convert into the lower form…


str_ireplce() is kind of magic function which will automatically understand the lower and upper value itself and then replace it …



No comments:

Post a Comment