Using PHP, I would like to encode specific characters (the >
and <
characters) within the attribute values for any tag.
For example, <input type="text" data-name="Oliver<>Nassar">
would become <input type="text" data-name="Oliver<>Nassar">
.
I'm not picky regarding the attribute name (eg. data-name
or value
attribute names). While I am happy to presume a whitespace character (\s
) before the attribute value (eg. <input data-name="...">
) it would be great if that were not a condition, such that I could meet cases such as <input type="text"data-name="Oliver<>Nassar">
I imagine PHPs preg_replace_callback
will be made use of, but as far the actual expression, I could use some help there.