Things About Web Design Logo

Things About Web Design

PHP CSS MySQL JS Scripts & Tutorials

TOP Snippets


.

PHP Bad Words Filter

The PHP foul language filter code in box below returns:

Oh ****, this *** code censors my darn text!

9


<?php
function filterwords($message){
 
$badwords = array('nasty''bum''snap');
 
$countwords sizeof($badwords);
 for (
$i 0$i $countwords$i++) {
  
$message preg_replace_callback('/\b' $badwords[$i] . '\b/i', function($matches){return str_repeat('*'strlen($matches[0]));}, $message);
 }
 return 
$message;
}
echo 
filterwords('Oh snap, this bum code censors my darn text!');
?>
.

PHP Form Processor

Below find PHP to submit form to SELF and create and write to file:

8


<?php
if(isset($_POST['submit'])) {
$textfile=fopen("data.txt""w+");
$file_contents=$_POST['name'];
fwrite($textfile$file_contents);
fclose($textfile);
echo 
"$file_contents";
}
?>
<form method="post" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']);?>"> <input type="text" name="name" placeholder="Name" /> <button type="submit" name="submit">Submit</button> </form> TRUE on success, FALSE and an error on failure. You can hide the error by adding an "@" in front of the function name. Possible values: "r" - Read only. Starts at the beginning of the file "r+" - Read/Write. Starts at the beginning of the file "w" - Write only. Opens and truncates the file; or creates a new file if it doesn't exist. Place file pointer at the beginning of the file "w+" - Read/Write. Opens and truncates the file; or creates a new file if it doesn't exist. Place file pointer at the beginning of the file "a" - Write only. Opens and writes to the end of the file or creates a new file if it doesn't exist "a+" - Read/Write. Preserves file content by writing to the end of the file "x" - Write only. Creates a new file. Returns FALSE and an error if file already exists "x+" - Read/Write. Creates a new file. Returns FALSE and an error if file already exists "c" - Write only. Opens the file; or creates a new file if it doesn't exist. Place file pointer at the beginning of the file "c+" - Read/Write. Opens the file; or creates a new file if it doesn't exist. Place file pointer at the beginning of the file "e" - Only available in PHP compiled on POSIX.1-2008 conform systems.
.

Password Generator

Below find a password generator script:

7

<form action="" method="POST"> Password Length: <input type="text" name="length" value="12"><br> <input type="checkbox" name="nums" value="nums" checked="yes">Include Numbers<br> <input type="checkbox" name="special" value="special">Include Special Characters<br> <input type="submit" name="sub" value="Generate"> </form>
<?php
if($_SERVER['REQUEST_METHOD'] == 'POST'){
    if(isset(
$_POST['nums']) && isset($_POST['special']))
    
$string 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&()_+';
    else if (isset(
$_POST['nums'])) $string 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890';
    else if (isset(
$_POST['special'])) $string 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&()_+';
    else 
$string 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
    
$length $_POST['length'];
    
$password "";
    for (
$i0$i<$length;$i++){
        
$password $password.$string[mt_rand(0strlen($string)-1)];
    }
    echo 
$password;
}
?>
.

Html Entities

Below are The most commonly used HTML Entities (often ' can be escaped like \'):

6

&lt; < | &gt; > | &quot; " | &apos ' | &bsol; \ | &copy; © |
.

Html Emojis

Below are some fun emojis when using character set: <meta charset="UTF-8">.
Check out more at: w3schools:

5

😍 &#128525 | 😎 &#128526 | 😀 &#128512 | 😇 &#128519
😉 &#128521 | 😊 &#128522
.

PHP Html Special Characters

The highlighted code below is used in your contact form PHP to remove html tags (security):

4


<form method="post" action="<?php echo htmlspecialchars("sendmail.php");?>"></form>

PHP Auto Copyright Year

The code below is an auto copyright update for the footer in websites: see php.net for more.

3


(&copy; is ©) Copyright 2017-<?php echo date("Y");?>
.

PHP Highlight File

The codes below can be used to return the PHP in external web page:

2


<?php show_source("page.php");?>
      
  
<?php highlight_file("page.php");?>
.

PHP Highlight String

The top code in box below returns the lower result:

1

<?php highlight_string('<?php $var = "This is a string."; echo $var;?>');?> returns: <?php $var "This is a string."; echo $var;?>