class Spoofchecker (View source)

This class is provided because Unicode contains large number of characters and incorporates the varied writing systems of the world and their incorrect usage can expose programs or systems to possible security attacks using characters similarity.

Provided methods allow to check whether an individual string is likely an attempt at confusing the reader (spoof detection), such as "pаypаl" spelled with Cyrillic 'а' characters.

Constants

SINGLE_SCRIPT_CONFUSABLE

MIXED_SCRIPT_CONFUSABLE

WHOLE_SCRIPT_CONFUSABLE

ANY_CASE

SINGLE_SCRIPT

INVISIBLE

CHAR_LIMIT

ASCII

HIGHLY_RESTRICTIVE

MODERATELY_RESTRICTIVE

MINIMALLY_RESTRICTIVE

UNRESTRICTIVE

SINGLE_SCRIPT_RESTRICTIVE

MIXED_NUMBERS

HIDDEN_OVERLAY

IGNORE_SPACE Since: 8.4

CASE_INSENSITIVE Since: 8.4

ADD_CASE_MAPPINGS Since: 8.4

SIMPLE_CASE_INSENSITIVE Since: 8.4

Methods

__construct()

(PHP >= 5.4.0, PECL intl >= 2.0.0)
Constructor

bool
isSuspicious(string $string, string $errorCode = null)

(PHP >= 5.4.0, PECL intl >= 2.0.0)
Checks if a given text contains any suspicious characters

bool
areConfusable(string $string1, string $string2, int $errorCode = null)

(PHP >= 5.4.0, PECL intl >= 2.0.0)
Checks if a given text contains any confusable characters

void
setAllowedLocales(string $locales)

(PHP >= 5.4.0, PECL intl >= 2.0.0)
Locales to use when running checks

void
setChecks(int $checks)

(PHP >= 5.4.0, PECL intl >= 2.0.0)
Set the checks to run

void
setRestrictionLevel(int $level)

Set the restriction level

void
setAllowedChars(string $pattern, int $patternOptions = 0)

Set the set of characters allowed when running checks

Details

__construct()

(PHP >= 5.4.0, PECL intl >= 2.0.0)
Constructor

bool isSuspicious(string $string, string $errorCode = null)

(PHP >= 5.4.0, PECL intl >= 2.0.0)
Checks if a given text contains any suspicious characters

Parameters

string $string

string $errorCode

[optional]

Return Value

bool

Returns true if there are suspicious characters, false otherwise.

bool areConfusable(string $string1, string $string2, int $errorCode = null)

(PHP >= 5.4.0, PECL intl >= 2.0.0)
Checks if a given text contains any confusable characters

Parameters

string $string1

string $string2

int $errorCode

[optional]

Return Value

bool

Returns true if two given strings can be confused, false otherwise.

void setAllowedLocales(string $locales)

(PHP >= 5.4.0, PECL intl >= 2.0.0)
Locales to use when running checks

Parameters

string $locales

Return Value

void

void setChecks(int $checks)

(PHP >= 5.4.0, PECL intl >= 2.0.0)
Set the checks to run

Parameters

int $checks

Return Value

void

No value is returned.

void setRestrictionLevel(int $level)

Set the restriction level

Sets the restriction level of SpoofChecker::isSuspicious.

Parameters

int $level

The restriction level of SpoofChecker::isSuspicious. One of Spoofchecker::ASCII, Spoofchecker::SINGLE_SCRIPT_RESTRICTIVE, Spoofchecker::HIGHLY_RESTRICTIVE, Spoofchecker::MODERATELY_RESTRICTIVE, Spoofchecker::MINIMALLY_RESTRICTIVE, or Spoofchecker::UNRESTRICTIVE. Defaults to Spoofchecker::HIGHLY_RESTRICTIVE.

Return Value

void

void setAllowedChars(string $pattern, int $patternOptions = 0)

Since: 8.4

Set the set of characters allowed when running checks

Restricts the characters that are considered acceptable by subsequent checks to the set described by pattern. Any character outside of this set causes Spoofchecker::isSuspicious to report a result.

Parameters

string $pattern
int $patternOptions

Return Value

void

Exceptions

ValueError