Hi internals.

I've been coding in PHP for 15 years now, and spend most days using it to
transform content into meaningful data.

Most of this is pulling out prices and attributes of certain products from
HTML, for example, grabbing the price from content such as "Total price
including delivery: £15.00".

To grab the "15.00" from the string can take quite a few lines of PHP and
can be pretty cumbersome.

I've built some helper functions - substring, and it's case-insensitive
variant subistring to help.
Functions take in the string plus a to and from string, and return a trim'd
string found between the two.

So substring("Total price including delivery: £15.00", "£", "")
would return "15.00".
>From and to strings are optional and therefore return from the beginning or
to the end.

In the past I hadn't thought about adding this to PHP core, but with the
introduction of str_starts/ends_with functions in PHP 8.0 I thought it may
be useful to include the sub(i)string building blocks too.

Implementation and tests can be found @
https://github.com/php/php-src/pull/6602

I'm sure the C implementation can be made a lot better, but it seems to work
OK at present.

This is my first e-mail to internals, so please excuse my naivety with
things, but hope this is useful.

Thanks,
Adam

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php

Reply via email to