regex - preg_replace HTML code in PHP -
i want remove string below html code <span style="font-size: 0.8px; letter-spacing: -0.8px; color: #ecf6f6">3</span>
so came regex.
$pattern = "/<span style=\"font-size: \\d(\\.\\d)?px; letter-spacing: -\\d(\\.\\d)?px; color: #\\w{6}\">\\w\\w?</span>/um";
however, regex doesn’t work. can point me did wrong. i'm new php.
when tested simple regex, works problem remains regex.
$str = $_post["txtarea"]; $pattern = $_post["regex"]; echo preg_replace($pattern, "", $str);
as advocate domdocument
job here, still need regular expression down line, ...
the expression px
numeric value can [\d.-]+
, since you're not trying validate anything.
the contents of span can simplified [^<]*
(i.e. opening bracket):
$re = '/<span style="font-size: [\d.-]+px; letter-spacing: [\d.-]+px; color: #[0-9a-f]{3,6}">[^<]*<\/span>/'; echo preg_replace($re, '', $str);
Comments
Post a Comment