Trying to parse HTML with regular expressions is cumbersome, error-prone and ultimately futile.
A safer (and potentially more efficient) approach would be to use the DOM extension instead.
The DOM extension is not a hard requirement for running WordPress - based on a brief look into the code, all calls to DOM extension functionality in the WP core seem to be guarded with class_exists() checks to prevent errors. However, the extension is enabled in PHP by default (see here), and is listed as a required module for WordPress in the WP Extension Check command for WP-CLI.
The following would be necessary to move to the DOM extension:
Trying to parse HTML with regular expressions is cumbersome, error-prone and ultimately futile.
A safer (and potentially more efficient) approach would be to use the DOM extension instead.
The DOM extension is not a hard requirement for running WordPress - based on a brief look into the code, all calls to DOM extension functionality in the WP core seem to be guarded with
class_exists()checks to prevent errors. However, the extension is enabled in PHP by default (see here), and is listed as a required module for WordPress in the WP Extension Check command for WP-CLI.The following would be necessary to move to the DOM extension:
filter_*()functions (to get a before/after comparison)filter_*()functions using the DOM extension