PHP Classes

File: invalidcharacters.php

Recommend this page to a friend!
  Classes of Juan Chaves   Invalid Characters   invalidcharacters.php   Download  
File: invalidcharacters.php
Role: Example script
Content type: text/plain
Description: Class Invalid Characters
Class: Invalid Characters
Check if a string has any invalid characters
Author: By
Last change:
Date: 13 years ago
Size: 874 bytes
 

Contents

Class file image Download
<?php


//class invalid characters


class InvalidCharacters
{

private
$allowed;



public function
reviews_allowed($view)

{

$charactersok = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";//Please insert here the characters that you consider as valid.
          
for ($i=0; $i<strlen($view); $i++){
              if (
strpos($charactersok, substr($view,$i,1))===false){
            
$this->allowed=false;return $this->allowed;
              }
           }
       
$this->allowed=true;return $this->allowed;
}

public function
go()
    {
        if (
$this->allowed==true){return;}
        if (
$this->allowed==false){echo 'Invalid character(s)';exit();}
       
    }


}


//example of how to apply

$info=new InvalidCharacters();
$info->reviews_allowed("lkjiñ");//Please insert here the characters to be checked.
$info->go();
echo
"Ok";//The script continues here.
?>