DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
Securing Your Software Supply Chain with JFrog and Azure
Register Today

Trending

  • Effortlessly Streamlining Test-Driven Development and CI Testing for Kafka Developers
  • Integrating AWS With Salesforce Using Terraform
  • SRE vs. DevOps
  • Cucumber Selenium Tutorial: A Comprehensive Guide With Examples and Best Practices

Trending

  • Effortlessly Streamlining Test-Driven Development and CI Testing for Kafka Developers
  • Integrating AWS With Salesforce Using Terraform
  • SRE vs. DevOps
  • Cucumber Selenium Tutorial: A Comprehensive Guide With Examples and Best Practices
  1. DZone
  2. Data Engineering
  3. Data
  4. Blacklist String Validator Class

Blacklist String Validator Class

Snippets Manager user avatar by
Snippets Manager
·
May. 21, 07 · Code Snippet
Like (0)
Save
Tweet
Share
1.37K Views

Join the DZone community and get the full member experience.

Join For Free
Check string for forbidden stuff. The constructur needs one single string argument, that contains the URI to the blacklist.txt file. This list contains one word per line of words that must not occur in the string to validate.


validate("blabla")) echo "ok";
      else echo "failed";

   */

   class CheckContent
   {
      public $blacklistFN; // The textfile with the list of prohibited expressions
      public $content="";  // The content to check - A single string
      private $blacklistA=array();
      private $isValid=TRUE;

      // constructor
      public function CheckContent($blacklist)
      {
	 $this->isValid=TRUE;
	 $this->blacklistFN=$blacklist;
	 $this->content="EMPTY";
      }

      // Main Method
      public function validate($content)
      {
	 $this->content=$content;
	 if(!$this->readFile()) return FALSE;

	 foreach ($this->blacklistA as $a)
	 {
	    if(preg_match('/'.$a.'/i',$content)) $this->isValid=FALSE;
	 }
	 return $this->isValid;
      }

      // Read File
      private function readFile()
      {
	 $blacklistTemp=array();
	 $blacklistS=FALSE;
	 $blacklistS=file_get_contents($this->blacklistFN);
	 if (!$blacklistS) 
	  {
	     echo "*** ERROR from CheckContent:: - Could not read blacklist file: ".$this->blacklistFN;
	     return FALSE;
	  }
	 $blacklistTemp=explode("\n",$blacklistS);
	 // Clean array
	 $this->blacklistA=array();
	 // Only lines that contain letters or digits
	 foreach ($blacklistTemp as $a) if( ereg("[a-zA-Z0-9]",$a) ) array_push($this->blacklistA,trim($a));
	 sort($this->blacklistA); // Cosmetic ;-)
	 return TRUE;
      }
   }


Strings Data Types

Opinions expressed by DZone contributors are their own.

Trending

  • Effortlessly Streamlining Test-Driven Development and CI Testing for Kafka Developers
  • Integrating AWS With Salesforce Using Terraform
  • SRE vs. DevOps
  • Cucumber Selenium Tutorial: A Comprehensive Guide With Examples and Best Practices

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com

Let's be friends: