[ad_1]
Facebook –
GitHub –
Google+ –
LinkedIn –
reddit –
Support –
thenewboston –
Twitter –
Beginner PHP Tutorial – 53 – Word Censoring Part 2
by
Tags:
Comments
45 responses to “Beginner PHP Tutorial – 53 – Word Censoring Part 2”
-
in case when we take input from user then what should we do
-
You can also use this code which is much more easier 馃檪
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
<textarea name="user_input" rows="10" cols="30" required oninvalid="this.setCustomValidity('Please enter some text.')"></textarea><br/><br/>
<input type="submit" name="submit" value="SUBMIT"/>
</form>
<hr/>
<?php
if(isset($_POST['user_input'])&& !empty($_POST['user_input'])){
$user_input = $_POST['user_input'];
$user_input_uc = strtoupper($user_input);
$substring = substr($user_input_uc, 1, -1);
$length = strlen($substring);
$censor = str_repeat('*', $length);
$replace = str_replace($substring, $censor, $user_input_uc);
echo $replace;
}
?>
</body>
</html> -
This code will help you censor any name no need to use array to mention the names …
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
<textarea name="user_input" rows="10" cols="30" required oninvalid="this.setCustomValidity('Please enter some text.')"></textarea><br/><br/>
<input type="submit" name="submit" value="SUBMIT"/>
</form>
<hr/>
<?php
if(isset($_POST['user_input'])&& !empty($_POST['user_input'])){
$user_input=$_POST['user_input'];
$user_input_uc=strtoupper($user_input);
$str1='';
$length=strlen($user_input_uc);
for($count=0;$count<$length;$count++){
if($count !=0 && $count !=($length-1)){
$str1 .= '*';
}
else{
$str1 .= $user_input_uc[$count];
}
}
echo $str1;
}
?>
</body>
</html> -
I am unable to get output for method post but method get is working
-
Why create a new $user_input_lc variable? Just call strtolower() within the call to str_replace():
$user_input_new = str_replace($find, $replace, strtolower($user_input));
Creating another variable just leads to yet more refactoring and makes the application more difficult to read.
-
<?php
$find = array('alex', 'billy', 'dale');
$replace = array('a**x', 'b***y', 'd**e');
if(isset($_POST['user_input'])&&!empty($_POST['user_input'])){
聽$user_input = strtolower($_POST['user_input']);
聽//$user_input_lc = strtolower($user_input);
聽$user_input_new= str_replace($find, $replace, $user_input);
聽echo $user_input_new;
聽
}
?>
<hr>
<form action="index.php" method="POST">
<textarea name="user_input" rows="6" cols="30"> </textarea> <br><br>
<input type="submit" value="Submit">
</form> -
Help plz my input is been seen on url tab
-
In an else statement when you have not set anything you can put $new_string = null; to stop PHP moaning about not setting a variable 馃槈
-
<br />
<b>Notice</b>: Undefined variable: user_input in <b>C:xampphtdocsNew foldertestindex.php</b> on line <b>17</b><br />getting this error
here is the code :
<?php
$find = array('alex','billy','dale');
$replace = array('a**x','b***y','d**e');if (isset($_POST['user_input'])&&!empty($_POST['user_input'])){
$user_input = $_POST['user_input'];
$user_input_new = str_replace($find,$replace,$user_input);echo $user_input_new;
}?>
<hr><form action= "index.php" method="POST">
<textarea name="user_input" rows="6" cols="30" ><?php echo $user_input; ?></textarea><br><br>
<input type="submit" value="Submit">
</form> -
I got this error in my <textarea></textarea> area:
Undefined variable: user_input in <b>C:xampphtdocsform.php</b> on line <b>19</b><br />
I have checked my code in line 19 and here is the code:
<textarea name="user_input" rows="7" cols="20"><?php echo $user_input; ?></textarea><br><br>
would appreciate any assistance… For some reason, my form works well without the <?php echo $user_input; ?>
-
hey guys! I am a bit confused here… so, I have a form where the user have to fill in and I called this register.html. Would I just add this bit of php code at the very top and that should work? How would I do this to check for all of my text areas? Would I have multiple if statements? This is a portion of my code:
<!doctype html>
<html lang="en">
<head><title>Registration</title>
</head>
<body>
<br />
<h1>Welcome to CyberPiano's Registration</h1>
<br />
<br />
<form name="mervinsForm" method="post">
Username: <input type="text" name="username" minlength="3" maxlength="20"/> <br /> <br />
Password: <input type="password" name="password" minlength="3" maxlength="20"/> <br /> <br />
Username and Password must be more than 3 characters and be less than 20 characters!: <br /> <br />
Email Address: <input type="text" name="Email" /> <br /> <br />
Male: <input type="radio" name="sex" value="male"/>
Female: <input type="radio" name="sex" value="female"/>
<br />
<br />
<input type="submit" value="Save"> -
<?php
$find = array('alex', 'billy', 'dale');
$replace = array('a**x', 'b***y', 'd**e');
$user_input = null;if (isset($_POST['user_input'])&&!empty($_POST['user_input'])) {
聽聽聽聽聽聽聽 $user_input = $_POST['user_input'];
}?>
<hr>
<form action="index.php" method="POST">
聽聽聽聽 聽
聽聽 <textarea name="user_input" rows="6" cols="30"><?php if (isset($_POST['user_input'])&&!empty($_POST['user_input']))echo $user_input; ?></textarea> <br /> <br />
聽 聽
聽聽聽 <input type="submit" value="Submit">
聽聽聽聽 聽
</form> -
Couldn't you use in_array?
-
can anyone tell me how can we code if we want to hid all the characters that user submit with * … that's useful for password inputs
-
The functions created in this tutorial don't seem to work for me.
聽Got it to work by changing the code though. -
I am getting 2 errors with this one.
Notice: Undefined variable: replace in blahbla/bla/line whatever, and
Notice: Undefined variable: user_input_new in blahbla/bla/line whateverI created $user_input = null; then when I added the $replace function, I got a syntax error with $user_input, eh??
-
<?php
$userip = '';
$find = array('ass','fuck');
$replace = array('@$$','#)(@');
if(isset($_POST['user_input']) && !empty($_POST['user_input'])) {
$userip = $_POST['user_input'];
$filter = str_replace($find, $replace, $userip);聽
echo $userip.' : '.$filter;
$userip = $filter;
}
?> -
thank you so much for all the videos!!!
-
Thanks Bucky , now we are actually implementing what we have learned in our past 50 lectures.
-
error_reporting(E_ALL ^ E_NOTICE); put this code if some text are appearing in your textbox
-
why in my browser always filled html coded on the textarea??
-
if you don't put that, the text you input in the textarea will be vanish once you clicked the submit. but i copied what alex did but the text in the textarea filled with some html codes. I fixed it by declaring the $user_input before the if statement.
-
I believe HTMLentities
-
to display what you input in textarea after you click the submit button
if you dont include the php part and you click the submit button
your textarea will be blank -
Why did he include "echo $user_input" inside the form?
i.e why did he include php part in that form?
my program is working fine without it. -
This is so fucking funny xD My little input: "I am going to Kittensing kill you! You motherKittenser! You're a fat Nice friend! You can suck my Plank! Stupid Chocolate!"
-
Ehm what does !empty mean?
-
these are awesome. thanks bro.
-
3:40 Bet he was thinking about saying "Dale with a big D" lol
-
I just wonder, how fun it should be to make these censoring dictionaries 馃榾
Just imagine how fucked up the guy making this dictionary should be to cover all the bad words xD -
try this $user = strip_tag($_POST['message'];
-
ireplace, sued by apple
-
if you go some videos back, you will find a replacer function, just use that to find and replace "< ? <" with a " " (nothing)
-
how to prevent ppl write characters like < ? < inside textarea for email or comment ???
-
tnk
-
Who the F**k is Beiber, that f*g is a piece of s**t
-
F*** Yeah!!! thanks Alex 馃檪
-
strtoupper
-
very helpful… thanks alex you are awesome…
-
the number of people that are watching this has dropped!! the less people view it the more i think i should preserver on !!
-
wow i figured the strtolower before watching the vid and it worked ,nice job Alex
-
how would you do it to maintain the uppercase letters?
-
As in every video the view count goes down. I feel more special
-
most instructive. many thanks.
-
nice 馃檪
Leave a Reply