Hello guys,Welcome back. Today i am here with another superb tutorial about word censoring in PHP. You might be thinking oh man its hard to develop . To be frank, Its like a child’s play. You just need to follow the logic. Well first of all let me explain what is “word censoring”. Well, sometime you can not use some words in any of the system and what if you used that word ? Then it simply replaced by other word. Well this is the small word censoring application. Suppose you want to hide particular character of your name then you may replace or hide them.



Let me go to the program, We will discuss about it via example

Source code for Word censoring in php

<?php

$find=array('jack','addy','larry');

$replace=array('**ck','**dy','**rry');

if(isset($_POST['user_input'])&&!empty($_POST['user_input']))

{

$user_input=$_POST['user_input'];

$user_input_new=str_ireplace($find,$replace,$user_input);

echo $user_input_new;
}

?>

<hr>

<form action="wordcensor.php" method="POST">

<textarea name="user_input" rows="6" col="30">

<?php

echo $user_input;

?>

</textarea>

<br>

<br>

<input type="Submit" value="Submit">

</form>


Output of Word censoring code in php



Logic of the Word censoring program in php

Well first we created one form which simply get some text from the user . We used “POST” method to post that text directly in php script.Then we simply set it to the variable named $user_input. Before setting up the desire text we have created two variables , find and replace. Find variable has array of particular strings and replace variable has array of particular words of find array in censored form. We have used star to censor
Why we used str_ireplace() function ?
Well if we directly input some words in capital form then it will not be censored so we used str_ireplace() function instead of replace. It will directly change all text into lowercase and then apply censoring to the particular word.
Hope you get the better idea for Word censoring in PHP. Enjoy coding . Do like fb page to support .Share it . 

By jigar

Leave a Reply

Your email address will not be published. Required fields are marked *