php - Check if website is in the blocked list -
am creating class handles redirection exterior locations. created method called isblocked
returns boolean result. function works follows:
it loops through $_blocked
variable , compares input string found, it returns true otherwise false. bellow actual incase explanation not enough.
public static function isblocked($location) { for($i = 0; $i < sizeof(self::$_blocked); $i++) { if(self::$_blocked[$i] === $location) { return true; } else { return false; } } }
this works perfectly, problem comes when example, lets "google.com" on list , input "www.google.com", return false. obvious since using identical operator ===
.
question following: there function in php work urls apart url_encode
& url_decode
? can create regular expression let me know if there other approach this.
thanks in advance.
it occurs me match backwards, since it's many one, 1 matching (sub)part of in stack. so, in case can use strpos()
(in lieu of regular expression):
function find_reverse_match($needle, $haystack) { $i = 0; $c = count($haystack); while ($i < $c) { if (strpos($needle, $haystack[$i++]) !== false) { return true; } } return false; }
Comments
Post a Comment