Beginner PHP Tutorial – 53 – Word Censoring Part 2

[ad_1]
Facebook –
GitHub –
Google+ –
LinkedIn –
reddit –
Support –
thenewboston –
Twitter –


Posted

in

by

Tags:

Comments

45 responses to “Beginner PHP Tutorial – 53 – Word Censoring Part 2”

  1. noman ali siraj Avatar

    in case when we take input from user then what should we do

  2. rohit chakrabarti Avatar

    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>

  3. rohit chakrabarti Avatar

    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>

  4. Bommadi Uday Kumar reddy Avatar

    I am unable to get output for method post but method get is working

  5. RR Dev Avatar

    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.

  6. Jad ABOU MALHAM Avatar

    <?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>

  7. Kunal Usapkar Avatar

    Help plz my input is been seen on url tab

  8. Booshotti Avatar

    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 馃槈

  9. saajanbedi Avatar

    <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>

  10. Mervin Lee Avatar

    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; ?>

  11. Mervin Lee Avatar

    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">

  12. V. Peters Avatar

    <?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>

  13. ShawnTD Avatar

    Couldn't you use in_array?

  14. Pouya Vagefi Avatar

    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

  15. daniel beeching Avatar

    The functions created in this tutorial don't seem to work for me.
    聽Got it to work by changing the code though.

  16. Robert Heselwood Avatar

    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 whatever

    I created $user_input = null; then when I added the $replace function, I got a syntax error with $user_input, eh??

  17. undefined Avatar

    <?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;
    }
    ?>

  18. Tali1562 Avatar

    thank you so much for all the videos!!!

  19. Danyal Abdullah Avatar

    Thanks Bucky , now we are actually implementing what we have learned in our past 50 lectures.

  20. ja dls Avatar

    error_reporting(E_ALL ^ E_NOTICE); put this code if some text are appearing in your textbox

  21. adilaga noval Avatar

    why in my browser always filled html coded on the textarea??

  22. Felix Montero Avatar

    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.

  23. bigfuzzydog Avatar

    I believe HTMLentities

  24. TheRizse Avatar

    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

  25. rahil471 Avatar

    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.

  26. movie627 Avatar

    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!"

  27. movie627 Avatar

    Ehm what does !empty mean?

  28. ArizonaGuy Avatar

    these are awesome. thanks bro.

  29. Dankest Elf Avatar

    3:40 Bet he was thinking about saying "Dale with a big D" lol

  30. Dankest Elf Avatar

    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

  31. xxiRaQiAtheistxx Avatar

    try this $user = strip_tag($_POST['message'];

  32. Puda Battur Avatar

    ireplace, sued by apple

  33. XDRosenheim Avatar

    if you go some videos back, you will find a replacer function, just use that to find and replace "< ? <" with a " " (nothing)

  34. BaliLandandVilla Avatar

    how to prevent ppl write characters like < ? < inside textarea for email or comment ???

  35. zanpaktuh Avatar

    Who the F**k is Beiber, that f*g is a piece of s**t

  36. Petros Siatos Avatar

    F*** Yeah!!! thanks Alex 馃檪

  37. syed samiuddin Avatar

    very helpful… thanks alex you are awesome…

  38. See Yung Phang Avatar

    the number of people that are watching this has dropped!! the less people view it the more i think i should preserver on !!

  39. Oletitptip Sm Avatar

    wow i figured the strtolower before watching the vid and it worked ,nice job Alex

  40. Rivieras Avatar

    how would you do it to maintain the uppercase letters?

  41. On belangerijk Avatar

    As in every video the view count goes down. I feel more special

  42. 专砖转 讟拽 Avatar

    most instructive. many thanks.

Leave a Reply

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