To ask the regular expression! Solution

Source: Internet
Author: User
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 !!
Testtesttes


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 ='
Testtesttes
';
$ Str = preg_replace ('/\ ]. *)? Rowspan = [\ "\ ']? ([0-9] +) [\ "\ ']? (\ S .*)? Colspan = [\ '\ "]? ([0-9] +) [\ '\ "]? ([^ \>]. *?)? \>/I ','



', $ Str );Echo htmlspecialchars ($ str );------ Solution --------------------: P$ Str ='
Testtesttes
';
$ 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 ('/\

', $ Str );

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.