KMP PHP API Reference

Matching
in package

A trait that provides useful methods to match HTML tag.

Table of Contents

Methods

findTagOrAttribute()  : bool
Check if the given input string contains an element with the given type name or attribute.
matchAttribute()  : bool
Check if the first tag found in the given input string contains an attribute with the given name and value.
matchTag()  : bool
Check if the given input string match the given tag, and returns an array of attributes if attrs is not null. This function does not work for "singleton" tags.

Methods

findTagOrAttribute()

Check if the given input string contains an element with the given type name or attribute.

public static findTagOrAttribute(string $tag, string $attrs, string $subject) : bool
Parameters
$tag : string

Tag name to search for, or null if not relevant.

$attrs : string

Array [name => value] for the attributes to search for, or null if not relevant. value can be null if only the name should be looked.

$subject : string

String to search.

Return values
bool

True if the given tag or given attribute is found.

matchAttribute()

Check if the first tag found in the given input string contains an attribute with the given name and value.

public static matchAttribute(string $attr, string $value, string $subject) : bool
Parameters
$attr : string

Name of the attribute.

$value : string

Value of the attribute.

$subject : string

String to search.

Return values
bool

True if an attribute with the given name/value was found, false otherwize.

matchTag()

Check if the given input string match the given tag, and returns an array of attributes if attrs is not null. This function does not work for "singleton" tags.

public static matchTag(string $tag, string $subject[, string &$content = null ][, array<string|int, mixed> &$attrs = null ]) : bool
Parameters
$tag : string

Tag to match (e.g. 'a', 'div', 'span').

$subject : string

String within which to match the tag.

$content : string = null

Content within the tag, if one was found.

$attrs : array<string|int, mixed> = null

Attributes of the tag, if one was found.

Return values
bool

True if the given tag was found, false otherwize.


        
On this page

Search results