I need the help of some RegEx-Experts to fix a bug in a WordPress-Plugin, which is no longer maintained by the author.
Inside the plugin there is the following php-sytax to find included scripts:
This line filters scripts no matter for what media they are written. To fix an bug this line must be changed, so that script tags with the parameter media="print" are not extracted.
How must this line be chanced that script tags with parameter media="print" are not affected?
See here for the topic in the WordPress-Support-Forum.
preg are not meant to match HTML tags. You'll never know where and how attributes will be defined :
Basically, you cannot handle that in a good way with pregs. I'd suggest you to extract the html you want to clean into some DOM (or even SimpleXML) object and get all script tags where attributes are "print" with an xpath function
A pretty simple approach would be:
It uses a
(?!..) negative assertion to look at each string part after a space. This will not exactly match HTML attributes, but is sufficient to detect the single case. You might need to add alternatives though (
media='print') because preg_match is looking for raw strings, not interpreting HTML-equivalent expressions. (Using DOM however would certainly be overkill for this task.)
to remove tags use strip_tag according to your need