To ask the regular expression !! & Lt; TABLE & nbsp; style & quot; WIDTH: & nbsp; 241pt; & nbsp; BORDER-COLLAPSE: & nbsp; collapse & quot; & nbsp; cellSpacing0 & nbsp; cellPadding0 & nbsp; rowspan6 & nb: Ask the regular expression !!
I want to use the preg_replace function to leave only two rowspan = 6 and colspan = 4 in the table attributes. how can I write the regular expressions in this function ??
------ Solution --------------------
$ Str ='
';
$ Str = preg_replace ('/\ ]. *)? Rowspan = [\ "\ ']? ([0-9] +) [\ "\ ']? (\ S .*)? Colspan = [\ '\ "]? ([0-9] +) [\ '\ "]? ([^ \>]. *?)? \>/I ','
', $ Str );Echo htmlspecialchars ($ str );------ Solution --------------------: P$ Str ='
';
$ Str = preg_replace ('/\ ]. *)? (Rowspan | colspan) = [\ "\ ']? ([0-9] +) [\ "\ ']? (\ S .*)? (Colspan | rowspan) = [\ '\ "]? ([0-9] +) [\ '\ "]? ([^ \>]. *?)? \>/I ','
] + (Rowspan | colspan) [\ s \ r \ n] * = [\ s \ r \ n] * ([\ "\ ']?) (\ D +) \ 2 [^ \>] + (colspan | rowspan) [\ s \ r \ n] * = [\ s \ r \ n] * ([\ '\ "]?) (\ D +) \ 5 [^ \>] * \>/I ','
', $ Str );Echo htmlspecialchars ($ str );------ Solution --------------------I also paste one. This Post considers the situations that can be ensured:1. avoid quotation marks, such as rowspan = "2;2. avoid leading and trailing spaces or line breaks, such as rowspan ="2 ". $ Str = preg_replace ('/\