Skip to main content
added 10 characters in body
Source Link
Vogel612
  • 25.5k
  • 7
  • 59
  • 141

You have a large amount of duplication in your conditions. additionally you have helluva lot of hardcoded strings all over the place. I suggest you change your structure to be something like:

<?php
$gamblingStrings = ["betting", "blackjack", "casino", "football", /*... */];
//Same for your other categories and then

if (matchesCategory($site, $gamblingStrings)) 
{
    //insert into gambling
}

//and the corresponding function
private function matchesCategory($site, $strings) {
    foreach ($strings as $matcher) 
    {
         if(strpos($site, $matcher) !== false) 
         {
             return true;
         }
    }
    return false;
}

Disclaimer: My PHP is extremely rusty, the provided samples could be quite borked. But I hope you get the gist of it ;)

You have a large amount of duplication in your conditions. additionally you have helluva lot of hardcoded strings all over the place. I suggest you change your structure to be something like:

<?php
$gamblingStrings = ["betting", "blackjack", "casino", "football", /*... */];
//Same for your other categories and then

if (matchesCategory($site, $gamblingStrings)) 
{
    //insert into gambling
}

//and the corresponding function
private function matchesCategory($site, $strings) {
    foreach ($strings as $matcher) 
    {
         if(strpos($site, $matcher)) 
         {
             return true;
         }
    }
    return false;
}

Disclaimer: My PHP is extremely rusty, the provided samples could be quite borked. But I hope you get the gist of it ;)

You have a large amount of duplication in your conditions. additionally you have helluva lot of hardcoded strings all over the place. I suggest you change your structure to be something like:

<?php
$gamblingStrings = ["betting", "blackjack", "casino", "football", /*... */];
//Same for your other categories and then

if (matchesCategory($site, $gamblingStrings)) 
{
    //insert into gambling
}

//and the corresponding function
private function matchesCategory($site, $strings) {
    foreach ($strings as $matcher) 
    {
         if(strpos($site, $matcher) !== false) 
         {
             return true;
         }
    }
    return false;
}

Disclaimer: My PHP is extremely rusty, the provided samples could be quite borked. But I hope you get the gist of it ;)

Source Link
Vogel612
  • 25.5k
  • 7
  • 59
  • 141

You have a large amount of duplication in your conditions. additionally you have helluva lot of hardcoded strings all over the place. I suggest you change your structure to be something like:

<?php
$gamblingStrings = ["betting", "blackjack", "casino", "football", /*... */];
//Same for your other categories and then

if (matchesCategory($site, $gamblingStrings)) 
{
    //insert into gambling
}

//and the corresponding function
private function matchesCategory($site, $strings) {
    foreach ($strings as $matcher) 
    {
         if(strpos($site, $matcher)) 
         {
             return true;
         }
    }
    return false;
}

Disclaimer: My PHP is extremely rusty, the provided samples could be quite borked. But I hope you get the gist of it ;)