Skip to content

Documentation

PHP SDK: Text, Prices, and Numbers

These methods are available through $ctx->text(). They transform values already obtained and do not request a website.

SDK reference

Methods

clean

clean(?string $value): string

Remove HTML tags, repeated spaces, and surrounding whitespace.

$name = $ctx->text()->clean('  <b>Drive belt</b>   for pump  ');

Result and notes. Returns Drive belt for pump. Returns an empty string for null.

money

money(?string $value): ?float

Turn a price string into a number, accounting for spaces, a comma, and a currency symbol.

$price = $ctx->text()->money('1 500,50 ₽');

Result and notes. Returns 1500.5 or null if no number is recognized. This method does not convert currencies.

digits

digits(?string $value): string

Keep digits only.

$number = $ctx->text()->digits('sku 001-42');

Result and notes. Returns the string 00142. Leading zeroes are preserved and letters removed, so this method is unsuitable for an alphanumeric product code.

between

between(string $subject, string $start, string $end): ?string

Take text between the first occurrence of start and the following occurrence of end.

$sku = $ctx->text()->between('Code: A-1; in stock: yes', 'Code: ', ';');

Result and notes. Returns A-1 or null if either boundary is missing.

extract

extract(string $pattern, string $subject, int $group = 1): ?string

Take one group from the first regular expression match.

$sku = $ctx->text()->extract('/Code:\s*([A-Z0-9-]+)/', 'Code: A-1');

Result and notes. Returns A-1 or null. group=1 is the default; group=0 returns the whole match.